docbrown/app/controllers/buffered_articles_controller.rb
rhymes 33a11adca8
Various optimizations (#6249) [deploy]
* 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
2020-02-25 13:42:24 -05:00

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