FIX: Prevent concurrent updates to top_topics (#19854)
to prevent lock timeouts
This commit is contained in:
parent
28078d78e2
commit
3030a53819
|
@ -5,6 +5,7 @@ class TopTopic < ActiveRecord::Base
|
||||||
|
|
||||||
# The top topics we want to refresh often
|
# The top topics we want to refresh often
|
||||||
def self.refresh_daily!
|
def self.refresh_daily!
|
||||||
|
DistributedMutex.synchronize("update_top_topics", validity: 5.minutes) do
|
||||||
transaction do
|
transaction do
|
||||||
remove_invisible_topics
|
remove_invisible_topics
|
||||||
add_new_visible_topics
|
add_new_visible_topics
|
||||||
|
@ -12,15 +13,18 @@ class TopTopic < ActiveRecord::Base
|
||||||
update_counts_and_compute_scores_for(:daily)
|
update_counts_and_compute_scores_for(:daily)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# We don't have to refresh these as often
|
# We don't have to refresh these as often
|
||||||
def self.refresh_older!
|
def self.refresh_older!
|
||||||
|
DistributedMutex.synchronize("update_top_topics", validity: 5.minutes) do
|
||||||
older_periods = periods - %i[daily all]
|
older_periods = periods - %i[daily all]
|
||||||
|
|
||||||
transaction { older_periods.each { |period| update_counts_and_compute_scores_for(period) } }
|
transaction { older_periods.each { |period| update_counts_and_compute_scores_for(period) } }
|
||||||
|
|
||||||
compute_top_score_for(:all)
|
compute_top_score_for(:all)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.refresh!
|
def self.refresh!
|
||||||
refresh_daily!
|
refresh_daily!
|
||||||
|
|
Loading…
Reference in New Issue