Skip to content

feat: add total users insight #15486

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

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix query
  • Loading branch information
BrunoQuaresma committed Nov 13, 2024
commit e77cf6726c5f65c29e0a01c79022beac285e35e9
18 changes: 11 additions & 7 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions coderd/database/queries/insights.sql
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,17 @@ GROUP BY utp.num, utp.template_ids, utp.name, utp.type, utp.display_name, utp.de
-- GetAccumulatedUsersInsights returns the accumulated number of users created
-- in the given timeframe. It returns the accumulated number of users for each date
-- within the specified timeframe, providing a running total of user sign-ups.
WITH RECURSIVE date_series AS (
SELECT @start_time::timestamptz AS date
UNION ALL
SELECT date + INTERVAL '1 day'
FROM date_series
WHERE date + INTERVAL '1 day' <= @end_time::timestamptz
)
SELECT
date_trunc('day', created_at)::date AS date,
COUNT(*) OVER (ORDER BY date_trunc('day', created_at)::date) AS total
d.date::date AS date,
(SELECT COUNT(*) FROM users u WHERE u.created_at <= d.date) AS total
FROM
users
WHERE
created_at >= @start_time::timestamptz
AND created_at < @end_time::timestamptz
date_series d
ORDER BY
date_trunc('day', created_at)::date;
d.date;