Skip to content

Commit

Permalink
Add cache reset buttons (#7060)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Sep 6, 2024
1 parent ed0f556 commit 0b598e4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/commands/track/retrieve_categories.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Track::RetrieveCategories
include Mandate

CACHE_KEY = "Track::RetrieveCategories".freeze

def call
Rails.cache.fetch(CACHE_KEY, expires_in: CACHE_EXPIRY) do
Track.order(:title).
Expand Down Expand Up @@ -53,8 +55,7 @@ def repo_topics
end.sort.to_h
end

CACHE_KEY = "Track::RetrieveCategories/1".freeze
CACHE_EXPIRY = 1.day.freeze
CATEGORIES = %w[wip-track unmaintained maintained maintained-autonomous maintained-solitary].freeze
private_constant :CACHE_KEY, :CACHE_EXPIRY, :CATEGORIES
private_constant :CACHE_EXPIRY, :CATEGORIES
end
4 changes: 2 additions & 2 deletions app/commands/track/retrieve_maintainers_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Track::RetrieveMaintainersStatus
MIN_REP_FOR_MEMBER = 50
MIN_REP_FOR_CANDIDATE = 100
LAST_NUMBER_OF_MONTHS_FOR_REP = 9
CACHE_KEY = "Track::RetrieveMaintainersStatus".freeze

def call
Rails.cache.fetch(CACHE_KEY, expires_in: CACHE_EXPIRY) do
Expand Down Expand Up @@ -110,7 +111,6 @@ def track_slugs = tracks.pluck(:slug)
memoize
def rep_cutoff_date = Time.zone.today - LAST_NUMBER_OF_MONTHS_FOR_REP.months

CACHE_KEY = "Track::RetrieveMaintainersStatus/5".freeze
CACHE_EXPIRY = 1.day.freeze
private_constant :CACHE_KEY, :CACHE_EXPIRY
private_constant :CACHE_EXPIRY
end
5 changes: 5 additions & 0 deletions app/controllers/maintaining/track_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ class Maintaining::TrackCategoriesController < Maintaining::BaseController
def index
@track_categories = Track::RetrieveCategories.()
end

def create
Rails.cache.delete Track::RetrieveCategories::CACHE_KEY
redirect_to maintaining_track_categories_path
end
end
5 changes: 5 additions & 0 deletions app/controllers/maintaining/track_maintainers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ class Maintaining::TrackMaintainersController < Maintaining::BaseController
def index
@track_maintainers_status = Track::RetrieveMaintainersStatus.()
end

def create
Rails.cache.delete Track::RetrieveMaintainersStatus::CACHE_KEY
redirect_to maintaining_track_maintainers_path
end
end
3 changes: 3 additions & 0 deletions app/views/maintaining/track_categories/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@
%tr
%td #{link_to track.title, Exercism::Routes.track_url(track)} (#{link_to 'GitHub repo', track.repo_url})
%td= category

%p.mb-16
= button_to "Clear cache", maintaining_track_categories_path, method: :post, form: { data: { turbo_confirm: "Are you sure? This is an expensive operation" } }, class: 'btn btn-warning'
3 changes: 3 additions & 0 deletions app/views/maintaining/track_maintainers/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@
%ul
- maintainers[:unlinked].each do |maintainer|
%li #{link_to maintainer[:github_username], "https://github.com/#{maintainer[:github_username]}"} (#{link_to 'commits', "#{track.repo_url}/commits?author=#{maintainer[:github_username]}"})

%p.mb-16
= button_to "Clear cache", maintaining_track_maintainers_path, method: :post, form: { data: { turbo_confirm: "Are you sure? This is an expensive operation" } }, class: 'btn btn-warning'
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
resources :submissions, only: [:index]
resources :exercise_representations
resources :site_updates, except: [:destroy]
resources :track_maintainers, only: [:index]
resources :track_categories, only: [:index]
resources :track_maintainers, only: %i[index create]
resources :track_categories, only: %i[index create]
end

namespace :contributing do
Expand Down

0 comments on commit 0b598e4

Please sign in to comment.