Fix slow hashtag timelines with any[] when using min_id (#41132)

This commit is contained in:
Hugo Gameiro authored and Claire committed 2026-10-28 18:54:14 +01:00
1 parent 43f1092217
commit f38ea42abf
2 files changed
+24

No files matched your search

+9
View File
@@ -30,6 +30,7 @@ class TagFeed < PublicFeed
scope.merge!(tagged_with_any_scope)
scope.merge!(tagged_with_all_scope)
scope.merge!(tagged_with_none_scope)
scope.merge!(tagged_with_cursor_scope(max_id, since_id, min_id))
scope.merge!(local_only_scope) if local_only?
scope.merge!(remote_only_scope) if remote_only?
scope.merge!(account_filters_scope) if account?
@@ -60,6 +61,14 @@ class TagFeed < PublicFeed
Status.group(:id).tagged_with_none(tags_for(options[:none]))
end
def tagged_with_cursor_scope(max_id, since_id, min_id)
lower_id = min_id.presence || since_id.presence
scope = Status.all
scope = scope.where(statuses_tags: { status_id: ...max_id }) if max_id.present?
scope = scope.where('statuses_tags.status_id > ?', lower_id) if lower_id.present?
scope
end
def tags_for(names)
Tag.matching_name(Array(names).take(LIMIT_PER_MODE)).pluck(:id) if names.present?
end
+15
View File
@@ -67,6 +67,21 @@ RSpec.describe TagFeed do
expect(results).to include(status)
end
it 'paginates with max_id' do
results = described_class.new(tag_cats, nil, any: [tag_dogs.name]).get(20, both.id)
expect(results).to contain_exactly(status_tagged_with_cats, status_tagged_with_dogs)
end
it 'paginates with since_id' do
results = described_class.new(tag_cats, nil, any: [tag_dogs.name]).get(20, nil, status_tagged_with_cats.id)
expect(results).to contain_exactly(status_tagged_with_dogs, both)
end
it 'paginates with min_id' do
results = described_class.new(tag_cats, nil, any: [tag_dogs.name]).get(20, nil, nil, status_tagged_with_cats.id)
expect(results).to contain_exactly(status_tagged_with_dogs, both)
end
context 'when both local_topic_feed_access and remote_topic_feed_access are disabled' do
before do
Setting.local_topic_feed_access = 'disabled'