* Pluck over map * Explain why map makes sense there * Refactor reactions controller a bit and iterate only once * Use group by instead of N counting queries * More positive * Simplify BufferedArticlesController * Less queries for MailchimpBot * Use Rails instead of SQL * Build comment_ids only when needed
21 lines
606 B
Ruby
21 lines
606 B
Ruby
class BufferedArticlesController < ApplicationController
|
|
# No authorization required for entirely public controller
|
|
|
|
def index
|
|
render json: { urls: buffered_articles_urls }.to_json
|
|
end
|
|
|
|
private
|
|
|
|
def buffered_articles_urls
|
|
relation = if Rails.env.production?
|
|
Article.where("last_buffered > ?", 24.hours.ago).
|
|
or(Article.where("published_at > ?", 20.minutes.ago))
|
|
else
|
|
Article.all
|
|
end
|
|
|
|
paths = relation.pluck(:path)
|
|
paths.map { |path| "https://#{ApplicationConfig['APP_DOMAIN']}#{path}" }
|
|
end
|
|
end
|