Skip to content

Commit

Permalink
Cache year.
Browse files Browse the repository at this point in the history
  need to cache against all params
  • Loading branch information
inulty-dfe committed Oct 29, 2024
1 parent 858bfe6 commit 0ff314a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/controllers/api/public/v1/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,31 @@ def index
private

def cached_course_count
if params[:no_cache]
year = permitted[:recruitment_cycle_year] || RecruitmentCycle.current.year

if permitted[:no_cache]
courses.count('course.id')
else
Rails.cache.fetch('api_course_count', expires_in: 5.minutes) do
Rails.cache.fetch("api_course_count_#{year}", expires_in: 5.minutes) do
courses.count('course.id')
end
end
end

def courses
@courses ||= APICourseSearchService.call(
filter: params[:filter],
sort: params[:sort],
filter: permitted[:filter],
sort: permitted[:sort],
course_scope: recruitment_cycle.courses
)
end

def include_param
params.fetch(:include, '')
permitted.fetch(:include, '')
end

def permitted
params.permit('page', 'no_cache', 'sort', 'per_page', 'courses', 'recruitment_cycle_year', 'include', 'filter' => %w[updated_since funding_type])
end
end
end
Expand Down

0 comments on commit 0ff314a

Please sign in to comment.