Skip to content

Commit

Permalink
Improve get stats db function performance
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
  • Loading branch information
tegioz committed Dec 19, 2023
1 parent fb55ea6 commit d16fa0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions database/migrations/functions/stats/get_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ returns setof json as $$
get_package_summary(jsonb_build_object('package_id', package_id)) as package,
sum(total) as total
from package_views
where date_trunc('year', day) = date_trunc('year', current_date)
and date_trunc('month', day) = date_trunc('month', current_date)
where date_trunc('year', day::timestamp) = date_trunc('year', current_timestamp)
and date_trunc('month', day::timestamp) = date_trunc('month', current_timestamp)
and package_id is not null
group by package_id
order by total desc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
create index if not exists package_views_year_month_idx on package_views (date_trunc('year', day::timestamp), date_trunc('month', day::timestamp));

---- create above / drop below ----

drop index if exists package_views_year_month_idx;

0 comments on commit d16fa0f

Please sign in to comment.