diff --git a/app/controllers/departments_controller.rb b/app/controllers/departments_controller.rb index f0fa8fe2c..b6ebcb2ef 100644 --- a/app/controllers/departments_controller.rb +++ b/app/controllers/departments_controller.rb @@ -1,6 +1,6 @@ class DepartmentsController < ApplicationController def for_option - render_ok(departments: Department.cached_names_data(current_school)) + render_ok(departments: current_school.departments.select(:id, :name).as_json) end private diff --git a/app/controllers/repertoires_controller.rb b/app/controllers/repertoires_controller.rb index 0ac78a15b..b62c94403 100644 --- a/app/controllers/repertoires_controller.rb +++ b/app/controllers/repertoires_controller.rb @@ -1,5 +1,5 @@ class RepertoiresController < ApplicationController def index - render_ok(repertoires: Repertoire.cache_data) + render_ok(repertoires: Repertoire.select(:id, :name).order(:created_at).as_json) end end \ No newline at end of file diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index ea94f4c69..f0dd6dd75 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -11,6 +11,6 @@ class SchoolsController < ApplicationController end def for_option - render_ok(schools: School.cached_names_data) + render_ok(schools: School.select(:id, :name).as_json) end end diff --git a/app/models/department.rb b/app/models/department.rb index c019862db..15a8a7c1b 100644 --- a/app/models/department.rb +++ b/app/models/department.rb @@ -2,23 +2,4 @@ class Department < ApplicationRecord belongs_to :school has_many :department_members, dependent: :destroy - - after_commit :reset_data_cache - - def self.cached_names_data(school) - Rails.cache.fetch(names_data_cache_key(school.id), expires_in: 7.days) do - school.departments.select(:id, :name).as_json - end - end - - private - - def reset_data_cache - # 清除部门名称缓存 - Rails.cache.delete(self.class.names_data_cache_key(school_id)) - end - - def self.names_data_cache_key(school_id) - "schools/#{school_id}/department_names_data" - end end diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index 140416658..72e1ebfff 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -3,23 +3,4 @@ class Repertoire < ApplicationRecord has_many :tag_repertoires, through: :sub_repertoires has_many :user_interests, dependent: :delete_all - - after_create_commit :reset_cache_data - after_update_commit :reset_cache_data - - def self.cache_data - Rails.cache.fetch(data_cache_key, expires_in: 1.days) do - Repertoire.select(:id, :name).order(:created_at).as_json - end - end - - def self.data_cache_key - 'repertoire/cache_data' - end - - private - - def reset_cache_data - Rails.cache.delete(self.class.data_cache_key) - end end diff --git a/app/models/school.rb b/app/models/school.rb index 983a93735..a0c829160 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -10,9 +10,6 @@ class School < ApplicationRecord has_many :ec_major_schools, :dependent => :destroy has_many :ec_majors, :through => :ec_major_schools - after_create_commit :reset_data_cache - after_update_commit :reset_data_cache - # 学校管理员 def manager?(user) ec_school_users.exists?(user_id: user.id) @@ -33,23 +30,4 @@ class School < ApplicationRecord def manage_permission?(user) manager?(user) || major_manager?(user) || course_manager?(user) end - - def self.cached_names_data - Rails.cache.fetch(names_data_cache_key, expires_in: 7.days) do - School.select(:id, :name).as_json - end - end - - private - - def reset_data_cache - # 清除学校名称缓存 - if new_record? || name_previously_changed? - Rails.cache.delete(self.class.names_data_cache_key) - end - end - - def self.names_data_cache_key - 'schools/names_data' - end end