From dcae5d02fc6bac36465a466086ba0f78dbd03107 Mon Sep 17 00:00:00 2001 From: Jon Betts Date: Thu, 15 Jun 2023 15:19:53 +0100 Subject: [PATCH] Swap the annotation type group info to a weekly grouping instead of daily This should cut down on the number of rows considerably --- .../07_annotation_type_group_counts/01_create_view.sql | 6 +++--- .../07_annotation_type_group_counts/02_initial_fill.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/01_create_view.sql b/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/01_create_view.sql index 027158a4d64..0140a40e59d 100644 --- a/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/01_create_view.sql +++ b/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/01_create_view.sql @@ -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 @@ -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; diff --git a/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/02_initial_fill.sql b/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/02_initial_fill.sql index 9107eaf4650..2b93fa04519 100644 --- a/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/02_initial_fill.sql +++ b/h/data_tasks/report/create_from_scratch/07_annotation_type_group_counts/02_initial_fill.sql @@ -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);