From 8fffa666dedd3e70853d6cc6e8803c1d79b7ec6d Mon Sep 17 00:00:00 2001 From: Toon Willems Date: Thu, 31 Oct 2024 14:50:53 +0100 Subject: [PATCH] Add cache service --- Gemfile.lock | 319 ++++++++---------- .../billable_metrics/destroy_service.rb | 2 + .../expression_cache_service.rb | 2 +- .../billable_metrics/update_service.rb | 2 +- app/services/cache_service.rb | 17 +- app/services/events/create_service.rb | 2 +- app/services/events/post_process_service.rb | 2 +- .../subscriptions/charge_cache_middleware.rb | 6 +- .../subscriptions/charge_cache_service.rb | 8 +- 9 files changed, 171 insertions(+), 189 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7acbd523ce1..eba3127e655 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/getlago/lago-expression.git - revision: 696e8dab910359c0385ca4c030a0f576357538e0 + revision: 503ed06dcd78ff994b4589046294e8366c8d6bcc glob: expression-ruby/lago-expression.gemspec specs: lago-expression (0.0.1) @@ -11,7 +11,7 @@ GIT GIT remote: https://github.com/glebm/i18n-tasks.git - revision: 592c86ba25bcbb6fa7ff614635dbc6336e52b1b5 + revision: 2cba1093e3c555b6664f62604a2e2f2dfe6f1a6e specs: i18n-tasks (1.0.14) activesupport (>= 4.0.2) @@ -118,7 +118,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) - adyen-ruby-api-library (9.9.0) + adyen-ruby-api-library (7.3.1) faraday after_commit_everywhere (1.4.0) activerecord (>= 4.2) @@ -130,20 +130,20 @@ GEM ast (2.4.2) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.999.0) - aws-sdk-core (3.211.0) + aws-partitions (1.967.0) + aws-sdk-core (3.201.5) aws-eventstream (~> 1, >= 1.3.0) - aws-partitions (~> 1, >= 1.992.0) + aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.9) jmespath (~> 1, >= 1.6.1) - aws-sdk-kms (1.95.0) - aws-sdk-core (~> 3, >= 3.210.0) + aws-sdk-kms (1.88.0) + aws-sdk-core (~> 3, >= 3.201.0) aws-sigv4 (~> 1.5) - aws-sdk-s3 (1.169.0) - aws-sdk-core (~> 3, >= 3.210.0) + aws-sdk-s3 (1.159.0) + aws-sdk-core (~> 3, >= 3.201.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.5) - aws-sigv4 (1.10.1) + aws-sigv4 (1.9.1) aws-eventstream (~> 1, >= 1.0.2) base64 (0.2.0) bcrypt (3.1.20) @@ -174,9 +174,9 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.3.4) connection_pool (2.4.1) - countries (7.0.0) + countries (5.7.2) unaccent (~> 0.3) - crack (1.0.0) + crack (0.4.6) bigdecimal rexml crass (1.0.6) @@ -196,34 +196,27 @@ GEM discard (1.3.0) activerecord (>= 4.2, < 8) docile (1.4.1) - dotenv (3.1.4) + dotenv (3.1.2) drb (2.2.1) erubi (1.13.0) - execjs (2.10.0) - factory_bot (6.5.0) + execjs (2.9.1) + factory_bot (6.4.6) activesupport (>= 5.0.0) - factory_bot_rails (6.4.4) - factory_bot (~> 6.5) + factory_bot_rails (6.4.3) + factory_bot (~> 6.4) railties (>= 5.0.0) - faker (3.5.1) + faker (3.4.2) i18n (>= 1.8.11, < 2) - faraday (2.12.0) - faraday-net_http (>= 2.0, < 3.4) - json + faraday (2.10.1) + faraday-net_http (>= 2.0, < 3.2) logger - faraday-net_http (3.3.0) - net-http - ffi (1.17.0) + faraday-net_http (2.1.0) ffi (1.17.0-aarch64-linux-gnu) ffi (1.17.0-aarch64-linux-musl) - ffi (1.17.0-arm-linux-gnu) - ffi (1.17.0-arm-linux-musl) ffi (1.17.0-arm64-darwin) - ffi (1.17.0-x86-linux-gnu) - ffi (1.17.0-x86-linux-musl) ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) - ffi (1.17.0-x86_64-linux-musl) + fiber-storage (1.0.0) formatador (1.1.0) globalid (1.2.1) activesupport (>= 6.1) @@ -239,12 +232,12 @@ GEM retriable (>= 2.0, < 4.a) google-apis-iamcredentials_v1 (0.21.0) google-apis-core (>= 0.15.0, < 2.a) - google-apis-storage_v1 (0.47.0) + google-apis-storage_v1 (0.43.0) google-apis-core (>= 0.15.0, < 2.a) google-cloud-core (1.7.1) google-cloud-env (>= 1.0, < 3.a) google-cloud-errors (~> 1.0) - google-cloud-env (2.2.1) + google-cloud-env (2.1.1) faraday (>= 1.0, < 3.a) google-cloud-errors (1.4.0) google-cloud-storage (1.52.0) @@ -256,38 +249,25 @@ GEM google-cloud-core (~> 1.6) googleauth (~> 1.9) mini_mime (~> 1.0) - google-protobuf (4.28.3) - bigdecimal - rake (>= 13) - google-protobuf (4.28.3-aarch64-linux) - bigdecimal - rake (>= 13) - google-protobuf (4.28.3-arm64-darwin) - bigdecimal - rake (>= 13) - google-protobuf (4.28.3-x86-linux) - bigdecimal - rake (>= 13) - google-protobuf (4.28.3-x86_64-darwin) - bigdecimal - rake (>= 13) - google-protobuf (4.28.3-x86_64-linux) - bigdecimal - rake (>= 13) - googleapis-common-protos-types (1.16.0) + google-protobuf (3.25.5-aarch64-linux) + google-protobuf (3.25.5-arm64-darwin) + google-protobuf (3.25.5-x86_64-darwin) + google-protobuf (3.25.5-x86_64-linux) + googleapis-common-protos-types (1.15.0) google-protobuf (>= 3.18, < 5.a) - googleauth (1.11.2) + googleauth (1.11.0) faraday (>= 1.0, < 3.a) google-cloud-env (~> 2.1) jwt (>= 1.4, < 3.0) multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) - graphql (1.13.23) + graphql (2.3.14) base64 - graphql-pagination (1.2.1) - graphql (~> 1.12) - guard (2.19.0) + fiber-storage + graphql-pagination (2.2.0) + graphql (~> 2.0) + guard (2.18.1) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) lumberjack (>= 1.0.12, < 2.0) @@ -303,32 +283,31 @@ GEM rspec (>= 2.99.0, < 4.0) hashdiff (1.1.1) hashie (5.0.0) - highline (3.1.1) - reline + highline (2.1.0) httpclient (2.8.3) - i18n (1.14.6) + i18n (1.14.5) concurrent-ruby (~> 1.0) io-console (0.7.2) - irb (1.14.1) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) jmespath (1.6.2) - json (2.7.5) - jwt (2.9.3) + json (2.7.2) + jwt (2.8.2) base64 kaminari-activerecord (1.2.2) activerecord kaminari-core (= 1.2.2) kaminari-core (1.2.2) - karafka (2.4.13) + karafka (2.4.8) base64 (~> 0.2) - karafka-core (>= 2.4.4, < 2.5.0) + karafka-core (>= 2.4.3, < 2.5.0) karafka-rdkafka (>= 0.17.2) waterdrop (>= 2.7.3, < 3.0.0) zeitwerk (~> 2.3) karafka-core (2.4.4) karafka-rdkafka (>= 0.15.0, < 0.18.0) - karafka-rdkafka (0.17.6) + karafka-rdkafka (0.17.3) ffi (~> 1.15) mini_portile2 (~> 2.6) rake (> 12) @@ -350,7 +329,7 @@ GEM railties (>= 4) request_store (~> 1.0) logstash-event (1.2.02) - loofah (2.23.1) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) lumberjack (1.2.10) @@ -373,16 +352,14 @@ GEM monetize (~> 1.9) money (~> 6.13) railties (>= 3.0) - msgpack (1.7.3) + msgpack (1.7.2) multi_json (1.15.0) multi_xml (0.7.1) bigdecimal (~> 3.1) multipart-post (2.4.1) mutex_m (0.2.0) nenv (0.3.0) - net-http (0.4.1) - uri - net-imap (0.5.0) + net-imap (0.4.14) date net-protocol net-pop (0.1.2) @@ -391,19 +368,12 @@ GEM timeout net-smtp (0.5.0) net-protocol - newrelic_rpm (9.14.0) - nio4r (2.7.4) - nokogiri (1.16.7) - mini_portile2 (~> 2.8.2) - racc (~> 1.4) + newrelic_rpm (9.12.0) + nio4r (2.7.3) nokogiri (1.16.7-aarch64-linux) racc (~> 1.4) - nokogiri (1.16.7-arm-linux) - racc (~> 1.4) nokogiri (1.16.7-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.7-x86-linux) - racc (~> 1.4) nokogiri (1.16.7-x86_64-darwin) racc (~> 1.4) nokogiri (1.16.7-x86_64-linux) @@ -418,10 +388,10 @@ GEM rack (>= 1.2, < 4) snaky_hash (~> 2.0) version_gem (~> 1.1) - opentelemetry-api (1.4.0) + opentelemetry-api (1.3.0) opentelemetry-common (0.21.0) opentelemetry-api (~> 1.0) - opentelemetry-exporter-otlp (0.29.0) + opentelemetry-exporter-otlp (0.28.1) google-protobuf (>= 3.18) googleapis-common-protos-types (~> 1.3) opentelemetry-api (~> 1.1) @@ -431,9 +401,9 @@ GEM opentelemetry-helpers-mysql (0.1.1) opentelemetry-api (~> 1.0) opentelemetry-common (~> 0.21) - opentelemetry-helpers-sql-obfuscation (0.2.0) + opentelemetry-helpers-sql-obfuscation (0.1.1) opentelemetry-common (~> 0.21) - opentelemetry-instrumentation-action_mailer (0.2.0) + opentelemetry-instrumentation-action_mailer (0.1.0) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-active_support (~> 0.1) opentelemetry-instrumentation-base (~> 0.22.1) @@ -441,26 +411,26 @@ GEM opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) opentelemetry-instrumentation-rack (~> 0.21) - opentelemetry-instrumentation-action_view (0.7.3) + opentelemetry-instrumentation-action_view (0.7.2) opentelemetry-api (~> 1.0) - opentelemetry-instrumentation-active_support (~> 0.6) + opentelemetry-instrumentation-active_support (~> 0.1) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-active_job (0.7.8) + opentelemetry-instrumentation-active_job (0.7.7) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) opentelemetry-instrumentation-active_model_serializers (0.20.2) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-active_record (0.8.0) + opentelemetry-instrumentation-active_record (0.7.4) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) opentelemetry-instrumentation-active_support (0.6.0) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-all (0.68.0) + opentelemetry-instrumentation-all (0.63.0) opentelemetry-instrumentation-active_model_serializers (~> 0.20.1) opentelemetry-instrumentation-aws_lambda (~> 0.1.0) - opentelemetry-instrumentation-aws_sdk (~> 0.7.0) + opentelemetry-instrumentation-aws_sdk (~> 0.5.0) opentelemetry-instrumentation-bunny (~> 0.21.0) opentelemetry-instrumentation-concurrent_ruby (~> 0.21.1) opentelemetry-instrumentation-dalli (~> 0.25.0) @@ -476,13 +446,13 @@ GEM opentelemetry-instrumentation-koala (~> 0.20.1) opentelemetry-instrumentation-lmdb (~> 0.22.1) opentelemetry-instrumentation-mongo (~> 0.22.1) - opentelemetry-instrumentation-mysql2 (~> 0.28.0) + opentelemetry-instrumentation-mysql2 (~> 0.27.0) opentelemetry-instrumentation-net_http (~> 0.22.1) - opentelemetry-instrumentation-pg (~> 0.29.0) + opentelemetry-instrumentation-pg (~> 0.28.0) opentelemetry-instrumentation-que (~> 0.8.0) opentelemetry-instrumentation-racecar (~> 0.3.0) - opentelemetry-instrumentation-rack (~> 0.25.0) - opentelemetry-instrumentation-rails (~> 0.32.0) + opentelemetry-instrumentation-rack (~> 0.24.0) + opentelemetry-instrumentation-rails (~> 0.31.0) opentelemetry-instrumentation-rake (~> 0.2.1) opentelemetry-instrumentation-rdkafka (~> 0.4.0) opentelemetry-instrumentation-redis (~> 0.25.1) @@ -491,11 +461,11 @@ GEM opentelemetry-instrumentation-ruby_kafka (~> 0.21.0) opentelemetry-instrumentation-sidekiq (~> 0.25.0) opentelemetry-instrumentation-sinatra (~> 0.24.0) - opentelemetry-instrumentation-trilogy (~> 0.60.0) + opentelemetry-instrumentation-trilogy (~> 0.59.0) opentelemetry-instrumentation-aws_lambda (0.1.1) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-aws_sdk (0.7.0) + opentelemetry-instrumentation-aws_sdk (0.5.4) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) opentelemetry-instrumentation-base (0.22.6) @@ -548,7 +518,7 @@ GEM opentelemetry-instrumentation-mongo (0.22.4) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-mysql2 (0.28.0) + opentelemetry-instrumentation-mysql2 (0.27.2) opentelemetry-api (~> 1.0) opentelemetry-helpers-mysql opentelemetry-helpers-sql-obfuscation @@ -556,26 +526,26 @@ GEM opentelemetry-instrumentation-net_http (0.22.7) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-pg (0.29.0) + opentelemetry-instrumentation-pg (0.28.0) opentelemetry-api (~> 1.0) opentelemetry-helpers-sql-obfuscation opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-que (0.8.4) + opentelemetry-instrumentation-que (0.8.3) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) opentelemetry-instrumentation-racecar (0.3.4) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-rack (0.25.0) + opentelemetry-instrumentation-rack (0.24.6) opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) - opentelemetry-instrumentation-rails (0.32.0) + opentelemetry-instrumentation-rails (0.31.2) opentelemetry-api (~> 1.0) - opentelemetry-instrumentation-action_mailer (~> 0.2.0) + opentelemetry-instrumentation-action_mailer (~> 0.1.0) opentelemetry-instrumentation-action_pack (~> 0.9.0) opentelemetry-instrumentation-action_view (~> 0.7.0) opentelemetry-instrumentation-active_job (~> 0.7.0) - opentelemetry-instrumentation-active_record (~> 0.8.0) + opentelemetry-instrumentation-active_record (~> 0.7.0) opentelemetry-instrumentation-active_support (~> 0.6.0) opentelemetry-instrumentation-base (~> 0.22.1) opentelemetry-instrumentation-rake (0.2.2) @@ -603,7 +573,7 @@ GEM opentelemetry-api (~> 1.0) opentelemetry-instrumentation-base (~> 0.22.1) opentelemetry-instrumentation-rack (~> 0.21) - opentelemetry-instrumentation-trilogy (0.60.0) + opentelemetry-instrumentation-trilogy (0.59.3) opentelemetry-api (~> 1.0) opentelemetry-helpers-mysql opentelemetry-helpers-sql-obfuscation @@ -619,34 +589,34 @@ GEM opentelemetry-semantic_conventions (1.10.1) opentelemetry-api (~> 1.0) os (1.1.4) - paper_trail (15.2.0) + paper_trail (15.1.0) activerecord (>= 6.1) request_store (~> 1.4) parallel (1.26.3) - parser (3.3.5.0) + parser (3.3.4.2) ast (~> 2.4.1) racc - pg (1.5.9) + pg (1.5.7) prism (1.2.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) psych (5.1.2) stringio - public_suffix (6.0.1) + public_suffix (5.1.1) puma (6.4.3) nio4r (~> 2.0) racc (1.8.1) - rack (3.1.8) - rack-cors (2.0.2) + rack (2.2.9) + rack-cors (1.1.1) rack (>= 2.0.0) - rack-session (2.0.0) - rack (>= 3.0.0) + rack-session (1.0.2) + rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rackup (2.1.0) - rack (>= 3) - webrick (~> 1.8) + rackup (1.0.0) + rack (< 3) + webrick rails (7.1.3.4) actioncable (= 7.1.3.4) actionmailbox (= 7.1.3.4) @@ -668,7 +638,7 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - rails-i18n (7.0.10) + rails-i18n (7.0.9) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) railties (7.1.3.4) @@ -702,7 +672,7 @@ GEM redlock (2.0.6) redis-client (>= 0.14.1, < 1.0.0) regexp_parser (2.9.2) - reline (0.5.10) + reline (0.5.9) io-console (~> 0.5) representable (3.2.0) declarative (< 0.1.0) @@ -712,64 +682,74 @@ GEM rack (>= 1.4) retriable (3.1.2) rexml (3.3.9) - roda (3.85.0) + roda (3.83.0) rack rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) - rspec-core (3.13.2) + rspec-core (3.13.0) rspec-support (~> 3.13.0) - rspec-expectations (3.13.3) + rspec-expectations (3.13.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-graphql_matchers (1.4.0) - graphql (>= 1.10.12, < 2.0) + rspec-graphql_matchers (2.0.0.pre.rc.0) + graphql (~> 2.0) rspec (~> 3.0) - rspec-mocks (3.13.2) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-rails (7.0.1) - actionpack (>= 7.0) - activesupport (>= 7.0) - railties (>= 7.0) + rspec-rails (6.1.4) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) rspec-core (~> 3.13) rspec-expectations (~> 3.13) rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.1) - rubocop (1.66.1) + rubocop (1.65.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 2.4, < 3.0) - rubocop-ast (>= 1.32.2, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.33.0) + rubocop-ast (1.32.1) parser (>= 3.3.1.0) + rubocop-capybara (2.21.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.26.1) + rubocop (~> 1.61) rubocop-graphql (1.5.4) rubocop (>= 1.50, < 2) - rubocop-performance (1.22.1) + rubocop-performance (1.21.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.27.0) + rubocop-rails (2.25.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.52.0, < 2.0) + rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (3.2.0) + rubocop-rspec (2.31.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.29.1) rubocop (~> 1.61) rubocop-thread_safety (0.5.1) rubocop (>= 0.90.0) - ruby-lsp (0.20.1) + ruby-lsp (0.20.0) language_server-protocol (~> 3.17.0) prism (>= 1.2, < 2.0) rbs (>= 3, < 4) sorbet-runtime (>= 0.5.10782) - ruby-lsp-rails (0.3.21) + ruby-lsp-rails (0.3.19) ruby-lsp (>= 0.20.0, < 0.21.0) ruby-progressbar (1.13.0) sass-rails (6.0.0) @@ -797,7 +777,8 @@ GEM shellany (0.0.1) shoulda-matchers (6.4.0) activesupport (>= 5.2.0) - sidekiq (7.3.4) + sidekiq (7.3.1) + concurrent-ruby (< 2) connection_pool (>= 2.3.0) logger rack (>= 2.2.4) @@ -811,11 +792,11 @@ GEM docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) - simplecov-html (0.13.1) + simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - slim (5.2.1) - temple (~> 0.10.0) - tilt (>= 2.1.0) + slim (4.1.0) + temple (>= 0.7.6, < 0.9) + tilt (>= 2.0.6, < 2.1) slim-rails (3.6.3) actionpack (>= 3.1) railties (>= 3.1) @@ -823,7 +804,7 @@ GEM snaky_hash (2.0.1) hashie version_gem (~> 1.1, >= 1.1.1) - sorbet-runtime (0.5.11630) + sorbet-runtime (0.5.11602) sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) @@ -831,47 +812,46 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) - standard (1.41.1) + standard (1.40.0) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) - rubocop (~> 1.66.0) + rubocop (~> 1.65.0) standard-custom (~> 1.0.0) - standard-performance (~> 1.5) + standard-performance (~> 1.4) standard-custom (1.0.2) lint_roller (~> 1.0) rubocop (~> 1.50) - standard-performance (1.5.0) + standard-performance (1.4.0) lint_roller (~> 1.1) - rubocop-performance (~> 1.22.0) + rubocop-performance (~> 1.21.0) stringio (3.1.1) - stripe (13.1.0) - strong_migrations (2.0.2) + stripe (6.5.0) + strong_migrations (2.0.0) activerecord (>= 6.1) - temple (0.10.3) + temple (0.8.2) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) - thor (1.3.2) - tilt (2.4.0) + thor (1.3.1) + tilt (2.0.11) timecop (0.9.10) timeout (0.4.1) trailblazer-option (0.1.2) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - uglifier (4.2.1) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) unaccent (0.4.0) - unicode-display_width (2.6.0) + unicode-display_width (2.5.0) uniform_notifier (1.16.0) - uri (0.13.1) valvat (1.4.4) rexml (>= 3.2.7, < 4.0.0) version_gem (1.1.4) - waterdrop (2.8.0) + waterdrop (2.7.4) karafka-core (>= 2.4.3, < 3.0.0) - karafka-rdkafka (>= 0.17.5) + karafka-rdkafka (>= 0.15.1) zeitwerk (~> 2.3) - webmock (3.24.0) + webmock (3.23.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -879,26 +859,19 @@ GEM websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - with_advisory_lock (5.1.0) - activerecord (>= 6.1) - zeitwerk (>= 2.6) - zeitwerk (2.7.1) + with_advisory_lock (4.6.0) + activerecord (>= 4.2) + zeitwerk (2.6.17) PLATFORMS - aarch64-linux-gnu + aarch64-linux aarch64-linux-musl - arm-linux - arm-linux-gnu - arm-linux-musl - arm64-darwin - ruby - x86-linux - x86-linux-gnu - x86-linux-musl - x86_64-darwin + arm64-darwin-22 + arm64-darwin-23 + x86_64-darwin-21 + x86_64-darwin-22 + x86_64-darwin-23 x86_64-linux - x86_64-linux-gnu - x86_64-linux-musl DEPENDENCIES aasm diff --git a/app/services/billable_metrics/destroy_service.rb b/app/services/billable_metrics/destroy_service.rb index 29e09d30adf..0ee6f664372 100644 --- a/app/services/billable_metrics/destroy_service.rb +++ b/app/services/billable_metrics/destroy_service.rb @@ -10,6 +10,8 @@ def initialize(metric:) def call return result.not_found_failure!(resource: 'billable_metric') unless metric + BillableMetrics::ExpressionCacheService.expire_cache(metric.organization.id, metric.code) + draft_invoice_ids = Invoice.draft.joins(plans: [:billable_metrics]) .where(billable_metrics: {id: metric.id}).distinct.pluck(:id) diff --git a/app/services/billable_metrics/expression_cache_service.rb b/app/services/billable_metrics/expression_cache_service.rb index e554ce891c1..95c53f7e2b9 100644 --- a/app/services/billable_metrics/expression_cache_service.rb +++ b/app/services/billable_metrics/expression_cache_service.rb @@ -8,7 +8,7 @@ def initialize(organization_id, billable_metric_code) @organization_id = organization_id @billable_metric_code = billable_metric_code - super(nil) + super end def cache_key diff --git a/app/services/billable_metrics/update_service.rb b/app/services/billable_metrics/update_service.rb index d0d570df718..cadb15d8df5 100644 --- a/app/services/billable_metrics/update_service.rb +++ b/app/services/billable_metrics/update_service.rb @@ -42,7 +42,7 @@ def call billable_metric.expression = params[:expression] if params.key?(:expression) if params.key?(:expression) || params.key?(:field_name) - Rails.cache.delete("expression/#{organization.id}/#{billable_metric.code}") + BillableMetrics::ExpressionCacheService.expire_cache(organization.id, billable_metric.code) end end diff --git a/app/services/cache_service.rb b/app/services/cache_service.rb index 2d48bd6b5ba..b6299c601f1 100644 --- a/app/services/cache_service.rb +++ b/app/services/cache_service.rb @@ -1,17 +1,26 @@ # frozen_string_literal: true class CacheService < BaseService + def initialize(*, expires_in: nil) + @expires_in = expires_in + super(nil) + end + + def self.expire_cache(*, **) + new(*, **).expire_cache + end + def cache_key raise NotImplementedError end def call(&) - fetch(&) + Rails.cache.fetch(cache_key, expires_in:, &) end - def fetch(&) - Rails.cache.fetch(cache_key, &) - end + private + + attr_reader :expires_in def expire_cache Rails.cache.delete(cache_key) diff --git a/app/services/events/create_service.rb b/app/services/events/create_service.rb index dfb285043ad..fe7d14fc4b8 100644 --- a/app/services/events/create_service.rb +++ b/app/services/events/create_service.rb @@ -42,7 +42,7 @@ def call attr_reader :organization, :params, :timestamp, :metadata def pre_ingest(event) - field_name, expression = Rails.cache.fetch("expression/#{organization.id}/#{event.code}") do + field_name, expression = BillableMetrics::ExpressionCacheService.call(organization.id, event.code) do bm = organization.billable_metrics.with_expression.find_by(code: event.code) [bm&.field_name, bm&.expression] end diff --git a/app/services/events/post_process_service.rb b/app/services/events/post_process_service.rb index 88338d61a52..bafe0e2d719 100644 --- a/app/services/events/post_process_service.rb +++ b/app/services/events/post_process_service.rb @@ -90,7 +90,7 @@ def expire_cached_charges(subscriptions) charge_filter = ChargeFilters::EventMatchingService.call(charge:, event:).charge_filter active_subscription.each do |subscription| - Subscriptions::ChargeCacheService.new(subscription:, charge:, charge_filter:).expire_cache + Subscriptions::ChargeCacheService.expire_cache(subscription:, charge:, charge_filter:) end end end diff --git a/app/services/subscriptions/charge_cache_middleware.rb b/app/services/subscriptions/charge_cache_middleware.rb index b940e6205e2..623df007085 100644 --- a/app/services/subscriptions/charge_cache_middleware.rb +++ b/app/services/subscriptions/charge_cache_middleware.rb @@ -12,7 +12,7 @@ def initialize(subscription:, charge:, to_datetime:, cache: true) def call(charge_filter:) return yield unless cache - json = Rails.cache.fetch(cache_key(charge_filter), expires_in: cache_expiration) do + json = Subscriptions::ChargeCacheService.call(subscription:, charge:, charge_filter:, expires_in: cache_expiration) do yield.to_json end @@ -23,10 +23,6 @@ def call(charge_filter:) attr_reader :subscription, :charge, :to_datetime, :cache - def cache_key(charge_filter) - Subscriptions::ChargeCacheService.new(subscription:, charge:, charge_filter:).cache_key - end - def cache_expiration (to_datetime - Time.current).to_i.seconds end diff --git a/app/services/subscriptions/charge_cache_service.rb b/app/services/subscriptions/charge_cache_service.rb index b889475c5b4..6cf37323476 100644 --- a/app/services/subscriptions/charge_cache_service.rb +++ b/app/services/subscriptions/charge_cache_service.rb @@ -11,16 +11,18 @@ def self.expire_for_subscription(subscription) def self.expire_for_subscription_charge(subscription:, charge:) charge.filters.each do |filter| - new(subscription:, charge:, charge_filter: filter).expire_cache + expire_cache(subscription:, charge:, charge_filter: filter) end - new(subscription:, charge:).expire_cache + expire_cache(subscription:, charge:) end - def initialize(subscription:, charge:, charge_filter: nil) + def initialize(subscription:, charge:, charge_filter: nil, expires_in: nil) @subscription = subscription @charge = charge @charge_filter = charge_filter + + super(expires_in:) end # IMPORTANT