Optimize published_articles_by_tag fetch speed (#12584)
This commit is contained in:
parent
d45d9be7c6
commit
0f5da03ccb
2 changed files with 3 additions and 4 deletions
|
|
@ -28,11 +28,10 @@ module Articles
|
|||
end
|
||||
|
||||
def published_articles_by_tag
|
||||
articles = Article.published.limited_column_select
|
||||
articles = @tag.present? ? Tag.find_by(name: @tag).articles : Article
|
||||
articles.published.limited_column_select
|
||||
.includes(top_comments: :user)
|
||||
.page(@page).per(@number_of_articles)
|
||||
articles = articles.cached_tagged_with(@tag) if @tag.present? # More efficient than tagged_with
|
||||
articles
|
||||
end
|
||||
|
||||
# Timeframe values from Timeframe::DATETIMES
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ RSpec.describe Articles::Feeds::LargeForemExperimental, type: :service do
|
|||
describe "#published_articles_by_tag" do
|
||||
let(:unpublished_article) { create(:article, published: false) }
|
||||
let(:tag) { "foo" }
|
||||
let(:tagged_article) { create(:article, tags: tag) }
|
||||
let!(:tagged_article) { create(:article, tags: tag) }
|
||||
|
||||
it "returns published articles" do
|
||||
result = feed.published_articles_by_tag
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue