mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-02-18 03:45:23 +00:00
Updating the historical counts.
This commit is contained in:
parent
bc16cb8cb9
commit
a50528a5bc
1 changed files with 69 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue