Skip to content

Commit

Permalink
topic refresh also updates deleted posts count
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jan 9, 2017
1 parent 6f2ee4f commit a36e2b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions community/models/topics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ do
Posts = require("community.models").Posts
return db.update(self:table_name(), {
root_posts_count = db.raw("\n (select count(*) from " .. tostring(db.escape_identifier(Posts:table_name())) .. "\n where topic_id = " .. tostring(db.escape_identifier(self:table_name())) .. ".id\n and depth = 1)\n "),
deleted_posts_count = db.raw("\n (select count(*) from " .. tostring(db.escape_identifier(Posts:table_name())) .. "\n where topic_id = " .. tostring(db.escape_identifier(self:table_name())) .. ".id and\n deleted and\n moderation_log_id is null)\n "),
posts_count = db.raw("\n (select count(*) from " .. tostring(db.escape_identifier(Posts:table_name())) .. "\n where topic_id = " .. tostring(db.escape_identifier(self:table_name())) .. ".id and\n not deleted and\n moderation_log_id is null)\n ")
}, where)
end
Expand Down
7 changes: 7 additions & 0 deletions community/models/topics.moon
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Topics extends Model
and depth = 1)
"

deleted_posts_count: db.raw "
(select count(*) from #{db.escape_identifier Posts\table_name!}
where topic_id = #{db.escape_identifier @table_name!}.id and
deleted and
moderation_log_id is null)
"

posts_count: db.raw "
(select count(*) from #{db.escape_identifier Posts\table_name!}
where topic_id = #{db.escape_identifier @table_name!}.id and
Expand Down

0 comments on commit a36e2b6

Please sign in to comment.