Skip to content

Commit

Permalink
Move Caching Registrations in V2 from HTML to API Level (#10413)
Browse files Browse the repository at this point in the history
* Move Caching Registrations in V2 from HTML to API Level

* better cross table access for cache key and add competition.id
  • Loading branch information
FinnIckler authored Dec 11, 2024
1 parent 5dc9dd3 commit 7797893
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 11 additions & 2 deletions app/controllers/api/v1/registrations/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,17 @@ def validate_bulk_update_request

def list
competition_id = list_params
registrations = Registration.accepted.where(competition_id: competition_id)
render json: registrations.includes(:user).map { |r| r.to_v2_json }
competition = Competition.find(competition_id)
registrations = competition.registrations.accepted
payload = Rails.cache.fetch([
"registrations_v2_list",
competition.id,
competition.event_ids,
registrations.joins(:user).order(:id).pluck(:id, :updated_at, user: [:updated_at]),
]) do
registrations.includes(:user).map { |r| r.to_v2_json }
end
render json: payload
end

# To list Registrations in the admin view you need to be able to administer the competition
Expand Down
9 changes: 1 addition & 8 deletions app/views/registrations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<% provide(:title, I18n.t('registrations.list.title', comp: @competition.name)) %>

<%= render layout: "nav" do %>
<% cache [
"registrations_index",
@competition.events.pluck(:id),
@competition.registrations.accepted.joins(:user).order(:id).pluck(:id, :updated_at, :"users.updated_at"),
I18n.locale
] do %>
<%= react_component('RegistrationsV2/Registrations', { competitionInfo: @competition.to_competition_info }) %>
<% end %>
<%= react_component('RegistrationsV2/Registrations', { competitionInfo: @competition.to_competition_info }) %>
<% end %>

0 comments on commit 7797893

Please sign in to comment.