-
Notifications
You must be signed in to change notification settings - Fork 30
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
Introduce graphql-cache #411
Changes from all commits
034082d
87371bc
e533cb3
f9a26e2
98a07be
56e99b9
5d34353
3ecb973
70f48be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ gem 'puma', '~> 3.12' | |
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder | ||
# gem 'jbuilder', '~> 2.5' | ||
# Use Redis adapter to run Action Cable in production | ||
gem 'redis', '~> 4.0' | ||
gem 'hiredis' | ||
# Use ActiveModel has_secure_password | ||
# gem 'bcrypt', '~> 3.1.7' | ||
|
||
|
@@ -68,13 +68,14 @@ gem 'prometheus_exporter' | |
|
||
gem 'activerecord-import' | ||
gem 'oj' | ||
gem 'newrelic_rpm' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are simply not using it and it adds overhead to every API call |
||
gem 'gitlab-sidekiq-fetcher', require: 'sidekiq-reliable-fetch' | ||
|
||
gem 'uuid' | ||
|
||
gem 'openscap_parser', '~> 1.0.0' | ||
|
||
gem 'graphql-cache' | ||
|
||
group :development, :test do | ||
gem 'brakeman' | ||
gem 'byebug', platforms: %i[mri mingw x64_mingw] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,5 @@ class Schema < GraphQL::Schema | |
mutation Types::Mutation | ||
lazy_resolve(Promise, :sync) | ||
use GraphQL::Batch | ||
use GraphQL::Execution::Interpreter | ||
use GraphQL::Analysis::AST | ||
use GraphQL::Cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately the new interpreter is incompatible with gql-cache (https://graphql-ruby.org/queries/interpreter.html) (stackshareio/graphql-cache#71) |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
# rule results, compliant,and references | ||
module RulesPreload | ||
include GraphQL::Schema::Interface | ||
field_class GraphQL::Cache::Field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required for some reason? This module is implemented from classes which inherit from |
||
|
||
def rules(args = {}) | ||
context[:parent_profile_id] ||= {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
GraphQL::Cache.configure do |config| | ||
config.namespace = 'compliance' # Cache key prefix for keys generated by graphql-cache | ||
config.cache = Rails.cache # The cache object to use for caching | ||
config.logger = Rails.logger # Logger to receive cache-related log messages | ||
config.expiry = 15552000 # 6 months (in seconds) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably discuss this and even think more seriously about introducing an LRU cache redis instance directly. Fields are cached alongside its updated_at, e.g: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the old entries with older There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, that's why I'd want to go with an instance like https://redis.io/topics/lru-cache There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, that's why I'd want to go with an instance like https://redis.io/topics/lru-cache |
||
end | ||
|
||
module GraphQL | ||
module Cache | ||
module DeconstructorExtensions | ||
def perform | ||
return raw.value if method == 'lazy' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if raw.is_a?(Promise) | ||
raw.wait | ||
raw.value | ||
end | ||
super | ||
end | ||
end | ||
|
||
class Deconstructor | ||
prepend DeconstructorExtensions | ||
end | ||
|
||
class Key | ||
def to_s | ||
@to_s ||= [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This overrides the way the keys are set - I'll comment more on this in a few |
||
GraphQL::Cache.namespace, | ||
object_clause, | ||
arguments_clause, | ||
field_clause, | ||
].flatten.compact.join(':') | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a more performant version of the redis gem