Browse Source

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

pull/4/head
Akihiko Odaki (@fn_aki@pawoo.net) 6 years ago
committed by Eugen Rochko
parent
commit
60b2b56d38
2 changed files with 14 additions and 3 deletions
  1. +1
    -3
      app/lib/feed_manager.rb
  2. +13
    -0
      spec/lib/feed_manager_spec.rb

+ 1
- 3
app/lib/feed_manager.rb View File

@ -38,9 +38,7 @@ class FeedManager
end
def trim(type, account_id)
return unless redis.zcard(key(type, account_id)) > FeedManager::MAX_ITEMS
last = redis.zrevrange(key(type, account_id), FeedManager::MAX_ITEMS - 1, FeedManager::MAX_ITEMS - 1)
redis.zremrangebyscore(key(type, account_id), '-inf', "(#{last.last}")
redis.zremrangebyrank(key(type, account_id), '0', (-(FeedManager::MAX_ITEMS + 1)).to_s)
end
def push_update_required?(timeline_type, account_id)

+ 13
- 0
spec/lib/feed_manager_spec.rb View File

@ -131,4 +131,17 @@ RSpec.describe FeedManager do
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

Loading…
Cancel
Save