Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: analytics user usage #229

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading