-
-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add report_counts to post and comment aggregate tables. (#5219)
* Add report_counts to post and comment aggregate tables. - This adds a report_count and unresolved_report_count to the post and comment aggregate tables. - Useful for front-ends wishing to show report links. - Fixes #4163 * Updating the historical counts. * Switching from bigint to smallint. * Using dullbananas create_trigger function.
- Loading branch information
1 parent
41bd830
commit ba3d574
Showing
9 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ALTER TABLE post_aggregates | ||
DROP COLUMN report_count, | ||
DROP COLUMN unresolved_report_count; | ||
|
||
ALTER TABLE comment_aggregates | ||
DROP COLUMN report_count, | ||
DROP COLUMN unresolved_report_count; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
-- Adding report_count and unresolved_report_count | ||
-- to the post and comment aggregate tables | ||
ALTER TABLE post_aggregates | ||
ADD COLUMN report_count smallint NOT NULL DEFAULT 0, | ||
ADD COLUMN unresolved_report_count smallint NOT NULL DEFAULT 0; | ||
|
||
ALTER TABLE comment_aggregates | ||
ADD COLUMN report_count smallint NOT NULL DEFAULT 0, | ||
ADD COLUMN unresolved_report_count smallint 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; | ||
|