mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
FIX: update group.has_messages field weekly
This commit is contained in:
parent
34f98f362f
commit
d64853dfa0
2 changed files with 30 additions and 0 deletions
|
@ -308,6 +308,7 @@ class Group < ActiveRecord::Base
|
|||
def self.ensure_consistency!
|
||||
reset_all_counters!
|
||||
refresh_automatic_groups!
|
||||
refresh_has_messages!
|
||||
end
|
||||
|
||||
def self.reset_all_counters!
|
||||
|
@ -331,6 +332,18 @@ class Group < ActiveRecord::Base
|
|||
args.each { |group| refresh_automatic_group!(group) }
|
||||
end
|
||||
|
||||
def self.refresh_has_messages!
|
||||
exec_sql <<-SQL
|
||||
UPDATE groups g SET has_messages = false
|
||||
WHERE NOT EXISTS (SELECT tg.id
|
||||
FROM topic_allowed_groups tg
|
||||
INNER JOIN topics t ON t.id = tg.topic_id
|
||||
WHERE tg.group_id = g.id
|
||||
AND t.deleted_at IS NULL)
|
||||
AND g.has_messages = true
|
||||
SQL
|
||||
end
|
||||
|
||||
def self.ensure_automatic_groups!
|
||||
AUTO_GROUPS.each_key do |name|
|
||||
refresh_automatic_group!(name) unless lookup_group(name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue