mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-18 00:54:49 +01:00
Remove sort in Feed (#4050)
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.
This commit is contained in:
parent
a9c326b200
commit
f85dbe83c8
@ -20,8 +20,7 @@ class Feed
|
|||||||
max_id = '+inf' if max_id.blank?
|
max_id = '+inf' if max_id.blank?
|
||||||
since_id = '-inf' if since_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)
|
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
|
Status.where(id: unhydrated).cache_ids
|
||||||
unhydrated.map { |id| status_map[id] }.compact
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_database(limit, max_id, since_id)
|
def from_database(limit, max_id, since_id)
|
||||||
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe Feed, type: :model do
|
RSpec.describe Feed, type: :model do
|
||||||
describe '#get' 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)
|
account = Fabricate(:account)
|
||||||
Fabricate(:status, account: account, id: 1)
|
Fabricate(:status, account: account, id: 1)
|
||||||
Fabricate(:status, account: account, id: 2)
|
Fabricate(:status, account: account, id: 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user