This commit is contained in:
BoHung Chiu 2023-01-31 18:08:00 +08:00
parent d014391b9e
commit 52f8b5bf2c
2 changed files with 19 additions and 4 deletions

View File

@ -38,18 +38,30 @@ class AnnouncementSetting
before_save do
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
if self.enable_manually_sort_changed? && self.enable_manually_sort
AnnsCache.all.delete
Bulletin.index({approved: -1,is_hidden: 1,is_preview: 1, is_top: -1,sort_number: 1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true })
Bulletin.create_indexes
OrbitHelper::SharedHash["announcement"][:enable_manually_sort] = self.enable_manually_sort if can_update_shared_hash
if can_update_shared_hash
OrbitHelper::SharedMutex.synchronize do
OrbitHelper::SharedHash["announcement"][:enable_manually_sort] = self.enable_manually_sort
end
end
@need_update_bulletin = true
end
@need_update_bulletin = false
if self.enable_annc_dept_changed?
OrbitHelper::SharedHash["announcement"][:enable_annc_dept] = self.enable_annc_dept
if can_update_shared_hash
OrbitHelper::SharedMutex.synchronize do
OrbitHelper::SharedHash["announcement"][:enable_annc_dept] = self.enable_annc_dept
end
end
@need_update_bulletin = true
end
if self.annc_depts_changed?
OrbitHelper::SharedHash["announcement"][:annc_depts_translations] = self.annc_depts_translations
if can_update_shared_hash
OrbitHelper::SharedMutex.synchronize do
OrbitHelper::SharedHash["announcement"][:annc_depts_translations] = self.annc_depts_translations
end
end
@need_update_bulletin = true
end
end

View File

@ -120,6 +120,9 @@ class Bulletin
index({postdate: 1}, { unique: false, background: true })
index({is_top: -1,postdate: -1, _id: -1}, { unique: false, background: true })
index({approved: -1,is_hidden: 1,is_preview: 1, is_top: -1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true })
if AnnouncementSetting.pluck(:enable_manually_sort).first == true
index({approved: -1,is_hidden: 1,is_preview: 1, is_top: -1,sort_number: 1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true })
end
field :sort_number, type: Integer
field :annc_dept, type: Integer
def get_org_model