add: user and platform cache

This commit is contained in:
2021-06-08 11:51:46 +08:00
parent a5b98bcad4
commit 02fe8a8966
29 changed files with 866 additions and 138 deletions

View File

@@ -105,7 +105,8 @@ class Project < ApplicationRecord
has_many :pinned_projects, dependent: :destroy
has_many :has_pinned_users, through: :pinned_projects, source: :user
after_save :check_project_members
after_save :check_project_members, :reset_cache_data
after_destroy :reset_cache_data
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
@@ -113,6 +114,14 @@ class Project < ApplicationRecord
delegate :content, to: :project_detail, allow_nil: true
delegate :name, to: :license, prefix: true, allow_nil: true
def reset_cache_data
if changes[:user_id].present?
first_owner = Owner.find_by_id(changes[:user_id].first)
self.reset_user_cache_async_job(first_owner)
end
self.reset_platform_cache_async_job
self.reset_user_cache_async_job(self.owner)
end
def self.search_project(search)
ransack(name_or_identifier_cont: search)