FIX: drop fragment cache for flags (#28001)
Flags are stored in the memory of the process and a fragment cache is not necessary.
This commit is contained in:
parent
43aa47b118
commit
f41716d532
|
@ -1,16 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class PostActionType < ActiveRecord::Base
|
class PostActionType < ActiveRecord::Base
|
||||||
after_save :expire_cache
|
|
||||||
after_destroy :expire_cache
|
|
||||||
|
|
||||||
include AnonCacheInvalidator
|
include AnonCacheInvalidator
|
||||||
|
|
||||||
def expire_cache
|
|
||||||
ApplicationSerializer.expire_cache_fragment!(/\Apost_action_types_/)
|
|
||||||
ApplicationSerializer.expire_cache_fragment!(/\Apost_action_flag_types_/)
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_reader :flag_settings
|
attr_reader :flag_settings
|
||||||
|
|
||||||
|
@ -35,7 +27,6 @@ class PostActionType < ActiveRecord::Base
|
||||||
@all_flags = nil
|
@all_flags = nil
|
||||||
@flag_settings = FlagSettings.new
|
@flag_settings = FlagSettings.new
|
||||||
ReviewableScore.reload_types
|
ReviewableScore.reload_types
|
||||||
PostActionType.new.expire_cache
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def overridden_by_plugin_or_skipped_db?
|
def overridden_by_plugin_or_skipped_db?
|
||||||
|
|
|
@ -111,17 +111,13 @@ class SiteSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_action_types
|
def post_action_types
|
||||||
cache_fragment("post_action_types_#{I18n.locale}") do
|
types = ordered_flags(PostActionType.types.values)
|
||||||
types = ordered_flags(PostActionType.types.values)
|
ActiveModel::ArraySerializer.new(types).as_json
|
||||||
ActiveModel::ArraySerializer.new(types).as_json
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def topic_flag_types
|
def topic_flag_types
|
||||||
cache_fragment("post_action_flag_types_#{I18n.locale}") do
|
types = ordered_flags(PostActionType.topic_flag_types.values)
|
||||||
types = ordered_flags(PostActionType.topic_flag_types.values)
|
ActiveModel::ArraySerializer.new(types, each_serializer: TopicFlagTypeSerializer).as_json
|
||||||
ActiveModel::ArraySerializer.new(types, each_serializer: TopicFlagTypeSerializer).as_json
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_archetype
|
def default_archetype
|
||||||
|
|
|
@ -1,24 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe PostActionType do
|
RSpec.describe PostActionType do
|
||||||
describe "Callbacks" do
|
|
||||||
describe "#expiry_cache" do
|
|
||||||
it "should clear the cache on save" do
|
|
||||||
cache = ApplicationSerializer.fragment_cache
|
|
||||||
|
|
||||||
cache["post_action_types_#{I18n.locale}"] = "test"
|
|
||||||
cache["post_action_flag_types_#{I18n.locale}"] = "test2"
|
|
||||||
|
|
||||||
PostActionType.new(name_key: "some_key").save!
|
|
||||||
|
|
||||||
expect(cache["post_action_types_#{I18n.locale}"]).to eq(nil)
|
|
||||||
expect(cache["post_action_flag_types_#{I18n.locale}"]).to eq(nil)
|
|
||||||
ensure
|
|
||||||
ApplicationSerializer.fragment_cache.clear
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#types" do
|
describe "#types" do
|
||||||
context "when verifying enum sequence" do
|
context "when verifying enum sequence" do
|
||||||
before { @types = PostActionType.types }
|
before { @types = PostActionType.types }
|
||||||
|
|
Loading…
Reference in New Issue