From c73e3c55491e582d73dee0859598644e58daf8b1 Mon Sep 17 00:00:00 2001 From: glacials Date: Sun, 20 Oct 2024 19:52:41 -0700 Subject: [PATCH] Small query optimizations / cleanups --- app/views/layouts/application.slim | 6 +++--- app/views/shared/_run_table.slim | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/application.slim b/app/views/layouts/application.slim index 17dfa8f6..6ee0945a 100644 --- a/app/views/layouts/application.slim +++ b/app/views/layouts/application.slim @@ -120,7 +120,7 @@ html lang='en' small: #hide-survey-button.text-secondary style='cursor: pointer' no thanks a#survey-button.btn.btn-outline-warning.btn-block.mb-0.text-center href=survey_url ' Help us out by taking the Splits.io survey! - - entry = current_user.present? ? current_user.entries.nonghosts.active.first : nil + - entry = current_user&.entries.nonghosts.active.first - if entry.present? && request.path != race_path(entry.race) .p-1.col-md-6.mx-auto a.btn.btn-success.btn-block.mb-0.text-center.glow href=race_path(entry.race) @@ -134,8 +134,8 @@ html lang='en' = yield(:footer) .row .col-md-6.d-none.d-xl-block - - patrons = User.includes(:patreon, :twitch).joins(:patreon).where('patreon_users.pledge_cents >= 200') - - unless patrons.blank? + - patrons = Rails.cache.fetch('patrons', expires_in: 1.day) { User.includes(:patreon, :twitch).joins(:patreon).where('patreon_users.pledge_cents >= 200').all } + - unless patrons.empty? a> href=patreon_url span Thanks to our patrons! p diff --git a/app/views/shared/_run_table.slim b/app/views/shared/_run_table.slim index bddd29ee..c5bc7db2 100644 --- a/app/views/shared/_run_table.slim +++ b/app/views/shared/_run_table.slim @@ -1,8 +1,8 @@ - description ||= nil - cols ||= [:runner, :time, :name, :video, :rival, :uploaded] -/ This allows us to blindly check the keys for items instead of wraping in `try`s +/ This allows us to blindly check the keys for items instead of wrapping in `try`s - col_options = cols.to_h { |col| [col, []] }.merge(local_assigns.fetch(:col_options, {})) -- runs = order_runs(runs).page(params[:page]).includes(:user, :game, :category, :video, :segments) +- runs = order_runs(runs).page(params[:page]).includes(:user, :video, :segments, :category, game: [:srdc]) - if runs.none? - if description.present? h5.card-header.text-white = description