Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Healthcheck with redis + fix home page performance issue #1029

Merged
merged 4 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/api/v1/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def index
if archived
@no_tries = true
@no_teams = false
@cases = Case.where(archived: archived, owner_id: current_user.id).all
@cases = Case.where(archived: archived, owner_id: current_user.id).all.with_counts
else
@cases = current_user.cases_involved_with.not_archived.with_counts.preload(:tries, :teams,
:cases_teams)
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ class HomeController < ApplicationController
before_action :set_case, only: [ :case_prophet ]

def show
# with_counts adds a `case.queries_count` field, which avoids loading
# all queries and makes bullet happy.
@cases = @current_user.cases_involved_with.not_archived.with_counts
.includes([ :metadata, :queries ])
.includes([ :metadata ])
.order('`case_metadata`.`last_viewed_at` DESC, `cases`.`id` DESC')
.limit(10)
.limit(30)

@most_recent_cases = @cases[0...4].sort_by { |c| c.case_name.downcase }

Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_case.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<tr>
<th scope="row"><%= kase.id %></th>
<th scope="row"><%= kase.case_name %></th>
<td><%= kase.queries.count %></td>
<td><%= kase.queries_count %></td>
<td>
<% unless kase.last_score.blank? %>
<%= number_with_precision(kase.last_score.score, precision: 2) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_case_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</h5>

<div class="card-body">
<turbo-frame id="case_prophet_frame_<%= kase.id %>" src="<%= home_case_prophet_path(kase) %>">
<turbo-frame id="case_frame_<%= kase.id %>" src="<%= home_case_prophet_path(kase) %>">
<h5 class="card-title placeholder-glow"></h5>
<p class="card-text placeholder-glow">
<span class="placeholder col-11"></span>
Expand Down
13 changes: 6 additions & 7 deletions app/views/home/case_prophet.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<turbo-frame id="case_prophet_frame_<%= @case.id %>">
<% kase = @case %>
<h5 class="card-title"><%= number_with_precision(kase.last_score.score, precision: 2) unless kase.scores.empty? %> <%= kase.scorer.name %></h5>
<turbo-frame id="case_frame_<%= @case.id %>">
<h5 class="card-title"><%= number_with_precision(@case.last_score.score, precision: 2) unless @case.scores.empty? %> <%= @case.scorer.name %></h5>
<p class="card-text">
<% if kase.scores %>
<% if @case.scores %>

<%= kase.first_score.created_at.to_date.to_fs(:short) %>
<% if kase.scores.count > 1 and kase.first_score.created_at.to_date.to_fs(:short) != kase.last_score.updated_at.to_date.to_fs(:short) %>
- <%= kase.last_score.updated_at.to_date.to_fs(:short)%>
<%= @case.first_score.created_at.to_date.to_fs(:short) %>
<% if @case.scores.count > 1 and @case.first_score.created_at.to_date.to_fs(:short) != @case.last_score.updated_at.to_date.to_fs(:short) %>
- <%= @case.last_score.updated_at.to_date.to_fs(:short)%>
<% end %>
<% end %>
</p>
Expand Down
2 changes: 2 additions & 0 deletions config/cable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: quepid_production
ssl_params:
verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>
2 changes: 2 additions & 0 deletions config/initializers/healthcheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# -- Checks --
config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
# config.add_check :redis, -> { Redis.new().ping }
config.add_check :sidekiq, -> { raise StandardError, 'Sidekiq is down' if Sidekiq::ProcessSet.new.empty? }
# config.add_check :cache, -> { Rails.cache.read('some_key') }
# config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
end