mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Reduce number of Redis calls.
This commit is contained in:
parent
661ae38a03
commit
b7ac33464f
1 changed files with 8 additions and 5 deletions
|
@ -4,7 +4,7 @@ class RandomTopicSelector
|
||||||
BACKFILL_LOW_WATER_MARK = 500
|
BACKFILL_LOW_WATER_MARK = 500
|
||||||
|
|
||||||
def self.backfill(category = nil)
|
def self.backfill(category = nil)
|
||||||
exclude = category.try(:topic_id)
|
exclude = category&.topic_id
|
||||||
|
|
||||||
# don't leak private categories into the "everything" group
|
# don't leak private categories into the "everything" group
|
||||||
user = category ? CategoryFeaturedTopic.fake_admin : nil
|
user = category ? CategoryFeaturedTopic.fake_admin : nil
|
||||||
|
@ -28,10 +28,13 @@ class RandomTopicSelector
|
||||||
.pluck(:id)
|
.pluck(:id)
|
||||||
|
|
||||||
key = cache_key(category)
|
key = cache_key(category)
|
||||||
results.each do |id|
|
|
||||||
$redis.rpush(key, id)
|
if results.present?
|
||||||
end
|
$redis.multi do
|
||||||
|
$redis.rpush(key, results)
|
||||||
$redis.expire(key, 2.days)
|
$redis.expire(key, 2.days)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
results
|
results
|
||||||
end
|
end
|
||||||
|
@ -77,7 +80,7 @@ class RandomTopicSelector
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cache_key(category = nil)
|
def self.cache_key(category = nil)
|
||||||
"random_topic_cache_#{category.try(:id)}"
|
"random_topic_cache_#{category&.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue