Skip to content
Extraits de code Groupes Projets
Valider 60b2b56d rédigé par Akihiko Odaki (@fn_aki@pawoo.net)'s avatar Akihiko Odaki (@fn_aki@pawoo.net) Validation de Eugen Rochko
Parcourir les fichiers

Reduce number of commands in FeedManager#trim (#3989)

parent b6a19e7b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -38,9 +38,7 @@ class FeedManager ...@@ -38,9 +38,7 @@ class FeedManager
end end
def trim(type, account_id) def trim(type, account_id)
return unless redis.zcard(key(type, account_id)) > FeedManager::MAX_ITEMS redis.zremrangebyrank(key(type, account_id), '0', (-(FeedManager::MAX_ITEMS + 1)).to_s)
last = redis.zrevrange(key(type, account_id), FeedManager::MAX_ITEMS - 1, FeedManager::MAX_ITEMS - 1)
redis.zremrangebyscore(key(type, account_id), '-inf', "(#{last.last}")
end end
def push_update_required?(timeline_type, account_id) def push_update_required?(timeline_type, account_id)
......
...@@ -131,4 +131,17 @@ RSpec.describe FeedManager do ...@@ -131,4 +131,17 @@ RSpec.describe FeedManager do
end end
end end
end end
describe '#push' do
it 'trims timelines if they will have more than FeedManager::MAX_ITEMS' do
account = Fabricate(:account)
status = Fabricate(:status)
members = FeedManager::MAX_ITEMS.times.map { |count| [count, count] }
Redis.current.zadd("feed:type:#{account.id}", members)
FeedManager.instance.push('type', account, status)
expect(Redis.current.zcard("feed:type:#{account.id}")).to eq FeedManager::MAX_ITEMS
end
end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter