From 9085935cb4e45785f1971554f2d755192eb89388 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 29 Oct 2024 13:52:35 +0800 Subject: [PATCH] Fix `second_level_cache` method not found error. (#1440) --- app/models/application_record.rb | 2 ++ app/models/concerns/fake_second_cache.rb | 9 +++++++++ test/support/model.rb | 1 + 3 files changed, 12 insertions(+) create mode 100644 app/models/concerns/fake_second_cache.rb diff --git a/app/models/application_record.rb b/app/models/application_record.rb index a70cb31c40..9d0f0cd422 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -3,10 +3,12 @@ class ApplicationRecord < ActiveRecord::Base include RedisCountable include Countable + include FakeSecondCache scope :recent, -> { order(id: :desc) } scope :exclude_ids, ->(ids) { where.not(id: ids.map(&:to_i)) } scope :by_week, -> { where("created_at > ?", 7.days.ago.utc) } delegate :url_helpers, to: "Rails.application.routes" + end diff --git a/app/models/concerns/fake_second_cache.rb b/app/models/concerns/fake_second_cache.rb new file mode 100644 index 0000000000..fc62088b79 --- /dev/null +++ b/app/models/concerns/fake_second_cache.rb @@ -0,0 +1,9 @@ +# Add a fake second_level_cache method to the model for compatibility with the Homeland plugins. +module FakeSecondCache + extend ActiveSupport::Concern + + class_methods do + def second_level_cache(args) + end + end +end diff --git a/test/support/model.rb b/test/support/model.rb index f43b7bcd7f..e99870dea6 100644 --- a/test/support/model.rb +++ b/test/support/model.rb @@ -1,4 +1,5 @@ class CommentablePage < ApplicationRecord + second_level_cache expires_in: 2.weeks end class Monkey < ApplicationRecord