Skip to content

Use a cache #7923

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gem 'aws-sdk-sesv2'
gem 'anycable-rails', '~> 1.2.0'
gem 'grpc', '>= 1.53.0'
gem 'crawler_detect'
gem 'xxhash'

# Serving requests
gem 'puma', '~> 4.3'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
xxhash (0.6.0)
yard (0.9.36)
zeitwerk (2.6.8)

Expand Down Expand Up @@ -631,6 +632,7 @@ DEPENDENCIES
tzinfo-data
web-console (>= 3.3.0)
webmock
xxhash

RUBY VERSION
ruby 3.3.0p0
Expand Down
2 changes: 1 addition & 1 deletion app/assemblers/assemble_code_tag_samples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def samples
)
end

def track = params[:track_slug].present? && Track.find(params[:track_slug])
def track = params[:track_slug].present? && Track.cached.find_by!(slug: params[:track_slug])
def status = params.fetch(:status, :needs_tagging).to_sym
def page = [params[:page].to_i, 1].max
end
2 changes: 1 addition & 1 deletion app/assemblers/assemble_community_videos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def videos

memoize
def track
Track.find(params[:video_track_slug]) if params[:video_track_slug].present?
Track.cached.find_by!(slug: params[:video_track_slug]) if params[:video_track_slug].present?
end
end
2 changes: 1 addition & 1 deletion app/assemblers/assemble_contributors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def starting_rank

memoize
def track_id
Track.find(params[:track_slug]).id if params[:track_slug].present?
Track.cached.find_by!(slug: params[:track_slug]).id if params[:track_slug].present?
end

memoize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def representations
)
end

def track = Track.find_by(slug: params[:track_slug])
def track = Track.cached.find_by(slug: params[:track_slug])
def representer_version = track.representations.maximum(:representer_version) || 1
end
2 changes: 1 addition & 1 deletion app/assemblers/assemble_journey_overview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def call

private
def learning_tracks_data
user.user_tracks.includes(:track).map do |user_track|
user.user_tracks.map do |user_track|
track = user_track.track

first_completion = user_track.exercise_completion_dates.min
Expand Down
2 changes: 1 addition & 1 deletion app/assemblers/assemble_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def tasks

memoize
def track_id
Track.find(params[:track_slug]).id if params[:track_slug].present?
Track.cached.find_by!(slug: params[:track_slug]).id if params[:track_slug].present?
end
end
2 changes: 1 addition & 1 deletion app/commands/mentor/request/retrieve_exercises.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def call

memoize
def track
Track.find(track_slug)
Track.cached.find_by!(slug: track_slug)
end

memoize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def completions

memoize
def csharp_exercises
Track.find('csharp').practice_exercises.index_by(&:slug)
Track.cached.find_by!(slug: 'csharp').practice_exercises.index_by(&:slug)
rescue ActiveRecord::RecordNotFound
{}
end
Expand Down
2 changes: 1 addition & 1 deletion app/commands/user/insiders_status/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def update_to_eligible

def update_to_ineligible
user.update!(insiders_status: :ineligible)
user.preferences.update(theme: DEFAULT_THEME) if uses_insiders_only_theme?
user.preferences.update!(theme: DEFAULT_THEME) if uses_insiders_only_theme?
end

def uses_insiders_only_theme? = INSIDERS_ONLY_THEMES.include?(user.preferences.theme)
Expand Down
4 changes: 3 additions & 1 deletion app/commands/user/update_flair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class User::UpdateFlair

initialize_with :user

def call = user.update!(flair:)
def call
user.update!(flair:)
end

private
memoize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def disable

private
def use_solution
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
@exercise = @track.exercises.find(params[:exercise_slug])
user = User.find_by!(handle: params[:community_solution_handle])
@solution = @exercise.solutions.find_by!(user_id: user.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def destroy

private
def use_solution
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
@exercise = @track.exercises.find(params[:exercise_slug])
user = User.find_by!(handle: params[:community_solution_handle])
@solution = @exercise.solutions.published.find_by!(user_id: user.id)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/community_solutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index

private
def use_exercise
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
@exercise = @track.exercises.find(params[:exercise_slug])
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/community_videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def lookup
def create
if params[:track_slug].present?
begin
track = Track.find(params[:track_slug])
track = Track.cached.find_by!(slug: params[:track_slug])
rescue ActiveRecord::RecordNotFound
return render_track_not_found
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/concepts/makers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index

private
def use_concept
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
@concept = @track.concepts.find(params[:concept_slug])
end
end
2 changes: 1 addition & 1 deletion app/controllers/api/exercises/makers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index

private
def use_exercise
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
@exercise = @track.exercises.find(params[:exercise_slug])
end
end
2 changes: 1 addition & 1 deletion app/controllers/api/exercises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def start

private
def use_track
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
end

def use_exercise
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/export_solutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index

private
def use_track
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
rescue ActiveRecord::RecordNotFound
render_track_not_found
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/hiring_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class API::HiringController < API::BaseController
def testimonials
user = User.find_by(handle: 'bobahop')
testimonials = user.mentor_testimonials.published.joins(solution: { exercise: :track })
testimonials = testimonials.where('exercises.track_id': Track.find(params[:track]).id) if params[:track]
testimonials = testimonials.where('exercises.track_id': Track.cached.find_by!(slug: params[:track]).id) if params[:track]
testimonials = testimonials.where('exercises.title LIKE ?', "%#{params[:exercise]}%") if params[:exercise]
testimonials = testimonials.order(id: params[:order] == "newest_first" ? :desc : :asc)
testimonials = testimonials.page(params[:page]).per(20)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/mentoring/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class API::Mentoring::RequestsController < API::BaseController
def index
begin
if params[:track_slug].present?
track_id = Track.find(params[:track_slug]).id
track_id = Track.cached.find_by!(slug: params[:track_slug]).id
current_user.track_mentorships.update_all("last_viewed = (track_id = #{track_id})")
end
rescue StandardError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class API::Tracks::SolutionsForMentoringController < API::BaseController
def index
track = Track.find(params[:track_slug])
track = Track.cached.find_by!(slug: params[:track_slug])
solutions = Track::SearchSolutionsForMentoring.(current_user, track, page: params[:page])

render json: SerializePaginatedCollection.(
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/tracks/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def not_enabled

private
def use_track
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
rescue StandardError
render_404(:track_not_found)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/tracks/trophies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class API::Tracks::TrophiesController < API::BaseController
def index
track = Track.find(params[:track_slug])
track = Track.cached.find_by!(slug: params[:track_slug])

render json: { trophies: SerializeTrackTrophies.(track, current_user) }
end

def reveal
begin
track = Track.find(params[:track_slug])
track = Track.cached.find_by!(slug: params[:track_slug])
rescue StandardError
return render_404(:track_not_found, fallback_url: tracks_url)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/user_tracks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def leave

private
def use_track
@track = Track.find(params[:slug])
@track = Track.cached.find_by!(slug: params[:slug])
# TODO: Rescue and handle
@user_track = UserTrack.for!(current_user, @track)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module UseTrackExerciseSolutionConcern
extend Mandate::Memoize

def use_track!
@track = Track.find(params[:track_id])
@track = Track.cached.find_by!(slug: params[:track_id])
@user_track = UserTrack.for(current_user, @track)

render_404 unless @track.accessible_by?(current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def use_section
end

def use_track
@track = Track.find(params[:track_slug])
@track = Track.cached.find_by!(slug: params[:track_slug])
@nav_docs = Document.where(track_id: @track.id)

render_404 unless @track.accessible_by?(current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/impact_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ImpactController < ApplicationController
skip_before_action :authenticate_user!

def index
@track = Track.find(params[:track_slug]) if params[:track_slug].present?
@track = Track.cached.find_by!(slug: params[:track_slug]) if params[:track_slug].present?
@last_24_hours = last_24_hours
@last_month = last_month
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/maintaining/site_updates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Maintaining::SiteUpdatesController < Maintaining::BaseController
def index
@updates = SiteUpdate.sorted
@updates = @updates.for_track(Track.find(params[:track_slug])) if params[:track_slug].present?
@updates = @updates.for_track(Track.cached.find_by!(slug: params[:track_slug])) if params[:track_slug].present?
@updates = @updates.page(params[:page]).per(30)
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def index
return redirect_to dashboard_path if user_signed_in?

@tracks = Track.active.order(num_students: :desc).limit(12).to_a
@num_tracks = Track.active.count
@num_tracks = Track.num_active

@showcase_exercises = [
{
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def show
end

def gobridge
@track = Track.find('go')
@track = Track.cached.find_by!(slug: 'go')
@num_concepts = @track.concepts.count
@num_exercises = @track.exercises.count
@num_tasks = @track.tasks.count
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sitemaps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def profiles
end

def track
track = Track.find(params[:track_id])
track = Track.cached.find_by!(slug: params[:track_id])
pages = []
pages << [track_url(track), track.updated_at, :monthly, 0.9]
pages << [track_concepts_url(track), track.updated_at, :monthly, 0.85] if track.course?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/temp/tracks/exercises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Tracks::ExercisesController < ApplicationController

private
def use_track
@track = Track.find(params[:track_id])
@track = Track.cached.find_by!(slug: params[:track_id])
@user_track = UserTrack.for(current_user, @track)

render_404 unless @track.accessible_by?(current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tracks/approaches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def show

private
def use_solution
@track = Track.find(params[:track_id])
@track = Track.cached.find_by!(slug: params[:track_id])
@user_track = UserTrack.for(current_user, @track)
@exercise = @track.exercises.find(params[:exercise_id])
@solution = Solution.for(current_user, @exercise)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tracks/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def show

private
def use_solution
@track = Track.find(params[:track_id])
@track = Track.cached.find_by!(slug: params[:track_id])
@user_track = UserTrack.for(current_user, @track)
@exercise = @track.exercises.find(params[:exercise_id])
@solution = Solution.for(current_user, @exercise)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tracks/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def tooltip

private
def use_track
@track = Track.find(params[:track_id])
@track = Track.cached.find_by!(slug: params[:track_id])
@user_track = UserTrack.for(current_user, @track)

render_404 unless @track.accessible_by?(current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tracks/dig_deeper_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def tooltip_locked = render_template_as_json

private
def use_solution
@track = Track.find(params[:track_id])
@track = Track.cached.find_by!(slug: params[:track_id])
@user_track = UserTrack.for(current_user, @track)
@exercise = @track.exercises.find(params[:exercise_id])
@solution = Solution.for(current_user, @exercise)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tracks/mentor_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def show

private
def use_solution
@track = Track.find(params[:track_id])
@track = Track.cached.find_by!(slug: params[:track_id])
@user_track = UserTrack.for(current_user, @track)
@exercise = @track.exercises.find(params[:exercise_id])
@solution = Solution.for(current_user, @exercise)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/tracks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
user: current_user
)

@num_tracks = Track.active.count
@num_tracks = Track.num_active

# TODO: (Optional) Change this to only select the fields needed for an icon
@track_icon_urls = Track.active.order('rand()').limit(8).map(&:icon_url)
Expand Down Expand Up @@ -49,7 +49,7 @@ def join

private
def use_track
@track = Track.find(params[:id])
@track = Track.cached.find_by!(slug: params[:id])
@user_track = UserTrack.for(current_user, @track)

render_404 unless @track.accessible_by?(current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/react_components/modals/welcome_modal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def to_s
super(
"modals-welcome-modal",
{
num_tracks: ::Track.active.count,
num_tracks: ::Track.num_active,
links: {
hide_modal_endpoint: Exercism::Routes.hide_api_settings_introducer_path(slug),
api_user_endpoint: Exercism::Routes.api_user_url,
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/view_components/site_footer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def to_s
def cache_key
parts = digests
parts << Date.current.year
parts << ::Track.active.count
parts << ::Track.num_active
parts << user_part
parts << stripe_version
parts << "v3"
Expand Down
Loading