Skip to content

Commit

Permalink
Swap the annotation type group info to a weekly grouping instead of d…
Browse files Browse the repository at this point in the history
…aily

This should cut down on the number of rows considerably
  • Loading branch information
jon-betts committed Jun 15, 2023
1 parent 7d4030a commit dcae5d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CREATE MATERIALIZED VIEW report.annotation_type_group_counts AS (
authority_id,
group_id,
-- Cast to a date as it's 4 bytes instead of 8
DATE_TRUNC('day', created)::DATE AS created_day,
DATE_TRUNC('week', created)::DATE AS created_week,
CASE
WHEN ARRAY_LENGTH(parent_uuids, 1) IS NOT NULL
THEN 'reply'::report.annotation_sub_type
Expand All @@ -45,6 +45,6 @@ CREATE MATERIALIZED VIEW report.annotation_type_group_counts AS (
shared,
COUNT(1) AS count
FROM report.annotations
GROUP BY created_day, authority_id, group_id, sub_type, shared
ORDER BY created_day, authority_id, group_id, count DESC
GROUP BY created_week, authority_id, group_id, sub_type, shared
ORDER BY created_week, authority_id, group_id, count DESC
) WITH NO DATA;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
DROP INDEX IF EXISTS report.annotation_type_group_counts_created_day_authority_id_idx;
DROP INDEX IF EXISTS report.annotation_type_group_counts_created_week_authority_id_idx;

REFRESH MATERIALIZED VIEW report.annotation_type_group_counts;

ANALYSE report.annotation_type_group_counts;

-- A unique index is mandatory for concurrent updates used in the refresh
CREATE UNIQUE INDEX annotation_type_group_counts_created_day_authority_id_idx
ON report.annotation_type_group_counts (created_day, authority_id, group_id, sub_type, shared);
CREATE UNIQUE INDEX annotation_type_group_counts_created_week_authority_id_idx
ON report.annotation_type_group_counts (created_week, authority_id, group_id, sub_type, shared);

0 comments on commit dcae5d0

Please sign in to comment.