Skip to content

Commit

Permalink
Use cached registration status in list_index
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Jan 4, 2025
1 parent bbe5ee2 commit 2339187
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v0/competitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def competition_index

competitions = competitions_scope.search(params[:q], params: params)

serial_methods = ["short_display_name", "city", "country_iso2", "event_ids", "date_range", "latitude_degrees", "longitude_degrees", "registration_status"]
serial_methods = ["short_display_name", "city", "country_iso2", "event_ids", "date_range", "latitude_degrees", "longitude_degrees", "cached_registration_status"]
serial_includes = {}

serial_includes["delegates"] = { only: ["id", "name"], methods: [], include: ["avatar"] } if admin_mode
Expand Down
6 changes: 6 additions & 0 deletions app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,12 @@ def registration_status
end
end

def cached_registration_status
Rails.cache.fetch(["comp-registration-status", self.id], expires_in: 5.minutes) do
self.registration_status
end
end

def any_registrations?
self.registrations.any?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function ConditionalYearHeader({
}

function RegistrationStatus({ comp }) {
if (comp.registration_status === 'not_yet_opened') {
if (comp.cached_registration_status === 'not_yet_opened') {
return (
<Popup
trigger={<Icon name="clock" color="blue" />}
Expand All @@ -418,7 +418,7 @@ function RegistrationStatus({ comp }) {
/>
);
}
if (comp.registration_status === 'past') {
if (comp.cached_registration_status === 'past') {
return (
<Popup
trigger={<Icon name="user times" color="red" />}
Expand All @@ -428,7 +428,7 @@ function RegistrationStatus({ comp }) {
/>
);
}
if (comp.registration_status === 'full') {
if (comp.cached_registration_status === 'full') {
return (
<Popup
trigger={<Icon name="user clock" color="orange" />}
Expand All @@ -438,7 +438,7 @@ function RegistrationStatus({ comp }) {
/>
);
}
if (comp.registration_status === 'open') {
if (comp.cached_registration_status === 'open') {
return (
<Popup
trigger={<Icon name="user plus" color="green" />}
Expand Down

0 comments on commit 2339187

Please sign in to comment.