Updating the historical counts.

This commit is contained in:
Dessalines 2024-11-22 08:25:47 -05:00
parent bc16cb8cb9
commit a50528a5bc

View file

@ -8,3 +8,72 @@ ALTER TABLE comment_aggregates
ADD COLUMN report_count bigint NOT NULL DEFAULT 0,
ADD COLUMN unresolved_report_count bigint NOT NULL DEFAULT 0;
-- Update the historical counts
-- Posts
UPDATE
post_aggregates AS a
SET
report_count = cnt.count
FROM (
SELECT
post_id,
count(*) AS count
FROM
post_report
GROUP BY
post_id) cnt
WHERE
a.post_id = cnt.post_id;
-- The unresolved
UPDATE
post_aggregates AS a
SET
unresolved_report_count = cnt.count
FROM (
SELECT
post_id,
count(*) AS count
FROM
post_report
WHERE
resolved = 'f'
GROUP BY
post_id) cnt
WHERE
a.post_id = cnt.post_id;
-- Comments
UPDATE
comment_aggregates AS a
SET
report_count = cnt.count
FROM (
SELECT
comment_id,
count(*) AS count
FROM
comment_report
GROUP BY
comment_id) cnt
WHERE
a.comment_id = cnt.comment_id;
-- The unresolved
UPDATE
comment_aggregates AS a
SET
unresolved_report_count = cnt.count
FROM (
SELECT
comment_id,
count(*) AS count
FROM
comment_report
WHERE
resolved = 'f'
GROUP BY
comment_id) cnt
WHERE
a.comment_id = cnt.comment_id;