]> cat aescling's git repositories - mastodon.git/commitdiff
Remove sort in Feed (#4050)
authorAkihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp>
Mon, 3 Jul 2017 11:17:27 +0000 (20:17 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 3 Jul 2017 11:17:27 +0000 (13:17 +0200)
In from_redis method, statuses retrieved from the database was mapped to
the IDs retrieved from Redis. It was equivalent to order from high to low
because those IDs are sorted in the same order.
Statuses are ordered with the ID by default, so we do not have to reorder.
Sorting statuses in the database is even faster since the IDs are indexed
with B-tree.

app/models/feed.rb
spec/models/feed_spec.rb

index 5125e51ff824b22713e2213f102de2aece863a87..beb4a8de3fc89e4ac2dc6957352de8d0d7f88ec5 100644 (file)
@@ -20,8 +20,7 @@ class Feed
     max_id     = '+inf' if max_id.blank?
     since_id   = '-inf' if since_id.blank?
     unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:last).map(&:to_i)
-    status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h
-    unhydrated.map { |id| status_map[id] }.compact
+    Status.where(id: unhydrated).cache_ids
   end
 
   def from_database(limit, max_id, since_id)
index 1cdb3a7839f4d6d526d728a20959f3953cb241d6..1c377c17f396062d26b543d9a8a4e9d9750ee9b8 100644 (file)
@@ -2,7 +2,7 @@ require 'rails_helper'
 
 RSpec.describe Feed, type: :model do
   describe '#get' do
-    it 'gets statuses with ids in the range, maintining the order from Redis' do
+    it 'gets statuses with ids in the range' do
       account = Fabricate(:account)
       Fabricate(:status, account: account, id: 1)
       Fabricate(:status, account: account, id: 2)