FEATURE: add count of previous flags on the post

This commit is contained in:
Régis Hanol
2014-09-08 17:53:29 +02:00
parent 7d6f3a5089
commit 00bd665c96
5 changed files with 9 additions and 6 deletions

View File

@ -26,11 +26,8 @@ module FlagQuery
p.post_number,
p.hidden,
p.deleted_at,
(SELECT pr.created_at
FROM post_revisions pr
WHERE pr.post_id = p.id AND pr.user_id = p.user_id
ORDER BY created_at DESC
LIMIT 1) AS last_revised_at
(SELECT created_at FROM post_revisions WHERE post_id = p.id AND user_id = p.user_id ORDER BY created_at DESC LIMIT 1) AS last_revised_at,
(SELECT COUNT(*) FROM post_actions WHERE (disagreed_at IS NOT NULL OR agreed_at IS NOT NULL OR deferred_at IS NOT NULL) AND post_id = p.id)::int AS previous_flags_count
FROM posts p
WHERE p.id in (:post_ids)").map_exec(OpenStruct, post_ids: post_ids)