From 6287566eb8a979236cf0fc9f6c89574c22fc9ab1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 18 Nov 2024 17:24:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fixed=20EduSetting=E5=80=BC1=E4=BD=8D?= =?UTF-8?q?=E6=97=B6=E5=A4=AA=E7=9F=AD=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/edu_setting.rb | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index f4a89c09b..64cec6e92 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -1,19 +1,19 @@ -# == Schema Information -# -# Table name: edu_settings -# -# id :integer not null, primary key -# name :string(255) -# value :string(255) -# created_at :datetime not null -# updated_at :datetime not null -# description :string(255) -# -# Indexes -# -# index_edu_settings_on_name (name) UNIQUE -# - +# == Schema Information +# +# Table name: edu_settings +# +# id :integer not null, primary key +# name :string(255) +# value :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# description :string(255) +# +# Indexes +# +# index_edu_settings_on_name (name) UNIQUE +# + class EduSetting < ApplicationRecord after_commit :expire_value_cache @@ -25,7 +25,11 @@ class EduSetting < ApplicationRecord end def self.get(key) - Rails.cache.fetch(value_cache_key(key), expires_in: 1.days) do + begin + Rails.cache.fetch(value_cache_key(key), expires_in: 1.days) do + find_by_name(key.to_s)&.value + end + rescue Exception => e find_by_name(key.to_s)&.value end end From 8b968d3f1af7def80da90de8ffde0d9843a32684 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 19 Nov 2024 08:33:15 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fixed=20EduSetting=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/edu_setting.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index 64cec6e92..4a38d6122 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -17,6 +17,7 @@ class EduSetting < ApplicationRecord after_commit :expire_value_cache + after_commit :clear_value_cache, on: :destroy scope :by_search, -> (keyword){ where("name LIKE :keyword OR value LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? } @@ -45,4 +46,8 @@ class EduSetting < ApplicationRecord def expire_value_cache Rails.cache.write(value_cache_key, value) end + + def clear_value_cache + Rails.cache.delete(value_cache_key) + end end From 61098942f7ba0730d87155f26adc61a8a824bd73 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 19 Nov 2024 09:07:09 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fixed=20EduSetting=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98after=5Fdestroy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/edu_setting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index 4a38d6122..dcb299d4c 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -17,7 +17,7 @@ class EduSetting < ApplicationRecord after_commit :expire_value_cache - after_commit :clear_value_cache, on: :destroy + after_destroy :clear_value_cache scope :by_search, -> (keyword){ where("name LIKE :keyword OR value LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? } From de71b5e19296e2e0fbafb0f561df3a54bb261a4e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 19 Nov 2024 10:29:50 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fixed=20EduSetting=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E9=99=A4=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/edu_setting.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index dcb299d4c..708aa625e 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -16,8 +16,8 @@ class EduSetting < ApplicationRecord - after_commit :expire_value_cache - after_destroy :clear_value_cache + after_commit :expire_value_cache, on: [:create, :update] + after_commit :clear_value_cache, on: :destroy scope :by_search, -> (keyword){ where("name LIKE :keyword OR value LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? }