-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9167 from CitizenLabDotCo/master
Release 2024-10-19-1
- Loading branch information
Showing
48 changed files
with
729 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
back/engines/commercial/aggressive_caching/aggressive_caching.gemspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
$LOAD_PATH.push File.expand_path('lib', __dir__) | ||
|
||
# Maintain your gem's version: | ||
require 'aggressive_caching/version' | ||
|
||
# Describe your gem and declare its dependencies: | ||
Gem::Specification.new do |s| | ||
s.name = 'aggressive_caching' | ||
s.version = AggressiveCaching::VERSION | ||
s.summary = 'Optionally enable aggressive caching for high traffic situations' | ||
s.authors = ['CitizenLab'] | ||
s.licenses = [Gem::Licenses::NONSTANDARD] # ['CitizenLab Commercial License V2'] | ||
s.files = Dir['{app,config,db,lib}/**/*', 'Rakefile', 'README.md'] | ||
|
||
s.add_dependency 'rails', '~> 7.0' | ||
s.add_dependency 'actionpack-action_caching', '~> 1.2' | ||
|
||
s.add_development_dependency 'rspec_api_documentation' | ||
s.add_development_dependency 'rspec-rails' | ||
end |
45 changes: 45 additions & 0 deletions
45
...l/aggressive_caching/app/controllers/aggressive_caching/patches/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module AggressiveCaching | ||
module Patches | ||
module ApplicationController | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# Needed to make actionpack-action_caching work with ActionController::API | ||
include ActionController::Caching | ||
# For some Reason, ActionController::Caching is not picking up the Rails | ||
# cache_store by itself. This initialization works, but could probaby be | ||
# improved | ||
self.cache_store = Rails.cache | ||
|
||
skip_after_action :verify_policy_scoped, if: :aggressive_caching_active? | ||
skip_after_action :verify_authorized, if: :aggressive_caching_active? | ||
end | ||
|
||
# Needed to make actionpack-action_caching work with ActionController::API. Fake implemenetation of what is normally provided by ActionController::Base | ||
def action_has_layout=(value) | ||
value | ||
end | ||
|
||
def aggressive_caching_active? | ||
AppConfiguration.instance.feature_activated?('aggressive_caching') | ||
end | ||
|
||
# Helpers for the subclasses to determinte for whom to cache | ||
def caching_and_visitor? | ||
aggressive_caching_active? && current_user.nil? | ||
end | ||
|
||
def caching_and_non_admin? | ||
aggressive_caching_active? && (current_user.nil? || current_user.normal_user?) | ||
end | ||
|
||
# Quite some API responses embed data about whether the current user | ||
# follows the returned resource. This lets us still cache those responses | ||
# for users that are not following anything | ||
def caching_and_not_following? | ||
aggressive_caching_active? && | ||
(current_user.nil? || (current_user.normal_user? && current_user&.follows&.none?)) | ||
end | ||
end | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
...ng/app/controllers/aggressive_caching/patches/web_api/v1/admin_publications_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module AdminPublicationsController | ||
def self.included(base) | ||
base.class_eval do | ||
# We can only cache for visitors, because permissions play a role in the admin publications shown | ||
with_options if: :caching_and_visitor? do | ||
caches_action :index, expires_in: 1.minute, cache_path: -> { request.query_parameters } | ||
caches_action :show, :status_counts, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
...ng/app/controllers/aggressive_caching/patches/web_api/v1/app_configurations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module AppConfigurationsController | ||
def self.included(base) | ||
base.class_eval do | ||
with_options if: :caching_and_non_admin? do | ||
caches_action :show, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
...ressive_caching/app/controllers/aggressive_caching/patches/web_api/v1/areas_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module AreasController | ||
def self.included(base) | ||
base.class_eval do | ||
with_options if: :caching_and_not_following? do | ||
caches_action :index, expires_in: 1.minute, cache_path: -> { request.query_parameters } | ||
caches_action :show, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
...sive_caching/app/controllers/aggressive_caching/patches/web_api/v1/comments_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module CommentsController | ||
def self.included(base) | ||
base.class_eval do | ||
with_options if: :caching_and_visitor? do | ||
caches_action :index, :children, expires_in: 1.minute, cache_path: -> { request.query_parameters } | ||
caches_action :show, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
...p/controllers/aggressive_caching/patches/web_api/v1/content_builder_layouts_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module ContentBuilderLayoutsController | ||
def self.included(base) | ||
base.class_eval do | ||
with_options if: :caching_and_non_admin? do | ||
caches_action :show, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
...essive_caching/app/controllers/aggressive_caching/patches/web_api/v1/events_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module EventsController | ||
def self.included(base) | ||
base.class_eval do | ||
with_options if: :caching_and_visitor? do | ||
caches_action :index, expires_in: 1.minute, cache_path: -> { request.query_parameters } | ||
caches_action :show, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
...ssive_caching/app/controllers/aggressive_caching/patches/web_api/v1/folders_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module FoldersController | ||
def self.included(base) | ||
base.class_eval do | ||
with_options if: :caching_and_visitor? do | ||
caches_action :index, expires_in: 1.minute, cache_path: -> { request.query_parameters } | ||
caches_action :show, :by_slug, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
...caching/app/controllers/aggressive_caching/patches/web_api/v1/idea_statuses_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module AggressiveCaching | ||
module Patches | ||
module WebApi | ||
module V1 | ||
module IdeaStatusesController | ||
def self.included(base) | ||
base.class_eval do | ||
with_options if: :caching_and_non_admin? do | ||
caches_action :index, expires_in: 1.minute, cache_path: -> { request.query_parameters } | ||
caches_action :show, expires_in: 1.minute | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.