diff --git a/app/services/notifications/update.rb b/app/services/notifications/update.rb index 77359287b..728b0b7ce 100644 --- a/app/services/notifications/update.rb +++ b/app/services/notifications/update.rb @@ -19,7 +19,9 @@ module Notifications notifiable_type: notifiable.class.name, action: action, ) - return if notifications.blank? + # as we only select the first notification right after, there is no need + # to load all of them in memory with `.blank?`, thus we choose `.none?` + return if notifications.none? new_json_data = notifications.first.json_data || {} new_json_data[notifiable.class.name.downcase] = public_send("#{notifiable.class.name.downcase}_data", notifiable) diff --git a/app/services/users/delete_articles.rb b/app/services/users/delete_articles.rb index 34e86fc13..f520fcf3c 100644 --- a/app/services/users/delete_articles.rb +++ b/app/services/users/delete_articles.rb @@ -3,7 +3,7 @@ module Users module_function def call(user, cache_buster = CacheBuster) - return unless user.articles.any? + return if user.articles.blank? virtual_articles = user.articles.map { |article| Article.new(article.attributes) } user.articles.find_each do |article| diff --git a/app/views/additional_content_boxes/boxes.html.erb b/app/views/additional_content_boxes/boxes.html.erb index ea8ad380c..6d1236ad5 100644 --- a/app/views/additional_content_boxes/boxes.html.erb +++ b/app/views/additional_content_boxes/boxes.html.erb @@ -6,7 +6,8 @@ follow_cue: @boosted_article.organization&.tag_line || @boosted_article.organization&.tag_line %> <% end %> -<% if @suggested_articles.any? %> +<%# the pattern .present?/.each has the advantage of issuing only a single SQL query to load objects in memory %> +<% if @suggested_articles.present? %> <% @suggested_articles.each do |article| %> <%= render "additional_content_boxes/article_box", article: article, diff --git a/app/views/articles/_sidebar.html.erb b/app/views/articles/_sidebar.html.erb index 89745ca97..b1cdfc234 100644 --- a/app/views/articles/_sidebar.html.erb +++ b/app/views/articles/_sidebar.html.erb @@ -11,7 +11,8 @@ <% @sponsorships = Sponsorship.gold.live.includes(:organization).order(featured_number: :asc) %> - <% if @sponsorships.any? %> + <%# the pattern .present?/.each has the advantage of issuing only a single SQL query to load objects in memory %> + <% if @sponsorships.present? %>
organizations