Skip to content

Commit

Permalink
Add fresh_when caching to API controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Mar 22, 2024
1 parent f60de4f commit 27f923c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v1/commits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ def index
end

@pagy, @commits = pagy_countless(@repository.commits.order('timestamp DESC'))
fresh_when @commits, public: true
end
end
2 changes: 2 additions & 0 deletions app/controllers/api/v1/hosts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class Api::V1::HostsController < Api::V1::ApplicationController
def index
@hosts = Host.all.visible.order('repositories_count DESC, commits_count DESC')
fresh_when @hosts, public: true
end

def show
@host = Host.find_by_name!(params[:id])
fresh_when @host, public: true
end
end
2 changes: 2 additions & 0 deletions app/controllers/api/v1/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def index
end

@pagy, @repositories = pagy_countless(scope)
fresh_when @repositories, public: true
end

def lookup
Expand All @@ -38,6 +39,7 @@ def lookup
def show
@host = Host.find_by_name!(params[:host_id])
@repository = @host.repositories.find_by!('lower(full_name) = ?', params[:id].downcase)
fresh_when @repository, public: true
end

def ping
Expand Down

0 comments on commit 27f923c

Please sign in to comment.