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

Track downloads statistics on timescaledb #4979

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update schema
  • Loading branch information
jonatas committed Dec 20, 2024
commit 06242b0172c2747b0c39127d8fc837a3635508b0
24 changes: 12 additions & 12 deletions db/downloads_schema.rb
Original file line number Diff line number Diff line change
@@ -37,60 +37,60 @@
create_hypertable "downloads", time_column: "created_at", chunk_time_interval: "1 day", compress_segmentby: "gem_name, gem_version", compress_orderby: "created_at DESC", compression_interval: "P7D"
create_continuous_aggregate("total_downloads_per_minute", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'PT10M'", end_offset: "INTERVAL 'PT1M'", schedule_interval: "INTERVAL '60'"}, materialized_only: true, finalized: true)
SELECT time_bucket('PT1M'::interval, created_at) AS created_at,
count(*) AS total
count(*) AS downloads
FROM downloads
GROUP BY (time_bucket('PT1M'::interval, created_at))
SQL

create_continuous_aggregate("total_downloads_per_hour", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'PT4H'", end_offset: "INTERVAL 'PT1H'", schedule_interval: "INTERVAL '3600'"}, materialized_only: true, finalized: true)
SELECT time_bucket('PT1H'::interval, created_at) AS created_at,
sum(total) AS total
sum(downloads) AS downloads
FROM total_downloads_per_minute
GROUP BY (time_bucket('PT1H'::interval, created_at))
SQL

create_continuous_aggregate("total_downloads_per_day", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'P3D'", end_offset: "INTERVAL 'P1D'", schedule_interval: "INTERVAL '86400'"}, materialized_only: true, finalized: true)
SELECT time_bucket('P1D'::interval, created_at) AS created_at,
sum(total) AS total
sum(downloads) AS downloads
FROM total_downloads_per_hour
GROUP BY (time_bucket('P1D'::interval, created_at))
SQL

create_continuous_aggregate("total_downloads_per_month", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'P3M'", end_offset: "INTERVAL 'P1D'", schedule_interval: "INTERVAL '86400'"}, materialized_only: true, finalized: true)
SELECT time_bucket('P1M'::interval, created_at) AS created_at,
sum(total) AS total
sum(downloads) AS downloads
FROM total_downloads_per_day
GROUP BY (time_bucket('P1M'::interval, created_at))
SQL

create_continuous_aggregate("downloads_by_gem_per_minute", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'PT10M'", end_offset: "INTERVAL 'PT1M'", schedule_interval: "INTERVAL '60'"}, materialized_only: true, finalized: true)
SELECT time_bucket('PT1M'::interval, created_at) AS created_at,
gem_name,
count(*) AS total
count(*) AS downloads
FROM downloads
GROUP BY (time_bucket('PT1M'::interval, created_at)), gem_name
SQL

create_continuous_aggregate("downloads_by_gem_per_hour", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'PT4H'", end_offset: "INTERVAL 'PT1H'", schedule_interval: "INTERVAL '3600'"}, materialized_only: true, finalized: true)
SELECT time_bucket('PT1H'::interval, created_at) AS created_at,
gem_name,
sum(total) AS total
sum(downloads) AS downloads
FROM downloads_by_gem_per_minute
GROUP BY (time_bucket('PT1H'::interval, created_at)), gem_name
SQL

create_continuous_aggregate("downloads_by_gem_per_day", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'P3D'", end_offset: "INTERVAL 'P1D'", schedule_interval: "INTERVAL '86400'"}, materialized_only: true, finalized: true)
SELECT time_bucket('P1D'::interval, created_at) AS created_at,
gem_name,
sum(total) AS total
sum(downloads) AS downloads
FROM downloads_by_gem_per_hour
GROUP BY (time_bucket('P1D'::interval, created_at)), gem_name
SQL

create_continuous_aggregate("downloads_by_gem_per_month", <<-SQL, refresh_policies: { start_offset: "INTERVAL 'P3M'", end_offset: "INTERVAL 'P1D'", schedule_interval: "INTERVAL '86400'"}, materialized_only: true, finalized: true)
SELECT time_bucket('P1M'::interval, created_at) AS created_at,
gem_name,
sum(total) AS total
sum(downloads) AS downloads
FROM downloads_by_gem_per_day
GROUP BY (time_bucket('P1M'::interval, created_at)), gem_name
SQL
@@ -99,7 +99,7 @@
SELECT time_bucket('PT1M'::interval, created_at) AS created_at,
gem_name,
gem_version,
count(*) AS total
count(*) AS downloads
FROM downloads
GROUP BY (time_bucket('PT1M'::interval, created_at)), gem_name, gem_version
SQL
@@ -108,7 +108,7 @@
SELECT time_bucket('PT1H'::interval, created_at) AS created_at,
gem_name,
gem_version,
sum(total) AS total
sum(downloads) AS downloads
FROM downloads_by_version_per_minute
GROUP BY (time_bucket('PT1H'::interval, created_at)), gem_name, gem_version
SQL
@@ -117,7 +117,7 @@
SELECT time_bucket('P1D'::interval, created_at) AS created_at,
gem_name,
gem_version,
sum(total) AS total
sum(downloads) AS downloads
FROM downloads_by_version_per_hour
GROUP BY (time_bucket('P1D'::interval, created_at)), gem_name, gem_version
SQL
@@ -126,7 +126,7 @@
SELECT time_bucket('P1M'::interval, created_at) AS created_at,
gem_name,
gem_version,
sum(total) AS total
sum(downloads) AS downloads
FROM downloads_by_version_per_day
GROUP BY (time_bucket('P1M'::interval, created_at)), gem_name, gem_version
SQL