Skip to content

Commit

Permalink
fix: analytics user usage (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Apr 16, 2024
1 parent 07b75f4 commit 4ea94a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 4 additions & 2 deletions packages/backend/src/api/v1/external-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const users = new Router({
users.get("/", checkAccess("users", "list"), async (ctx: Context) => {
const { projectId } = ctx.state

const { limit = "100", page = "0", search } = ctx.query
const { limit = "100", page = "0", search, days } = ctx.query

const daysNum = parseInt(days as string)

let searchQuery = sql``
if (search) {
Expand All @@ -26,7 +28,7 @@ users.get("/", checkAccess("users", "list"), async (ctx: Context) => {
created_at,
last_seen,
props,
(select coalesce(sum(cost), 0) from run where external_user_id = external_user.id) as cost
(select coalesce(sum(cost), 0) from run where external_user_id = external_user.id and run.created_at >= now() - interval '1 day' * ${daysNum}) as cost
from
external_user
where
Expand Down
8 changes: 3 additions & 5 deletions packages/frontend/utils/dataHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,18 @@ export function useRunsUsageByUser(range = null) {
}
}

// TODO: pagination
export function useAppUserList() {
export function useAppUserList(usageRange) {
const {
data: users,
isLoading,
isValidating,
} = useProjectSWR(`/external-users`)
} = useProjectSWR(`/external-users?days=${usageRange}`)

return { users, isLoading, isValidating }
}

// TODO
export function useAppUsers(usageRange = 30) {
const { users, isLoading } = useAppUserList()
const { users, isLoading } = useAppUserList(usageRange)

const maxLastSeen = new Date(
new Date().getTime() - usageRange * 24 * 60 * 60 * 1000,
Expand Down

0 comments on commit 4ea94a6

Please sign in to comment.