diff --git a/app/controllers/users/statistics_controller.rb b/app/controllers/users/statistics_controller.rb index 592a8be94..dffd3f607 100644 --- a/app/controllers/users/statistics_controller.rb +++ b/app/controllers/users/statistics_controller.rb @@ -188,30 +188,32 @@ class Users::StatisticsController < Users::BaseController @project_languages_count = time_filter(Project.where(user_id: observed_user.id), 'created_on').joins(:project_language).group("project_languages.name").count @platform_project_languages_count = time_filter(Project, 'created_on').joins(:project_language).group("project_languages.name").count else + @platform_result = Cache::V2::PlatformStatisticService.new.read + @user_result = Cache::V2::UserStatisticService.new(observed_user.id).read # 用户被follow数量 - @follow_count = Cache::UserFollowCountService.call(observed_user) - @platform_follow_count = Cache::PlatformFollowCountService.call + @follow_count = @user_result["follow-count"].to_i + @platform_follow_count = @platform_result["follow-count"].to_i # 用户pr数量 - @pullrequest_count = Cache::UserPullrequestCountService.call(observed_user) - @platform_pullrequest_count = Cache::PlatformPullrequestCountService.call + @pullrequest_count = @user_result["pullrequest-count"].to_i + @platform_pullrequest_count = @platform_result["pullrequest-count"].to_i # 用户issue数量 - @issues_count = Cache::UserIssueCountService.call(observed_user) - @platform_issues_count = Cache::PlatformIssueCountService.call + @issues_count = @user_result["issue-count"].to_i + @platform_issues_count = @platform_result["issue-count"].to_i # 用户总项目数 - @project_count = Cache::UserProjectCountService.call(observed_user) - @platform_project_count = Cache::PlatformProjectCountService.call + @project_count = @user_result["project-count"].to_i + @platform_project_count = @platform_result["project-count"].to_i # 用户项目被fork数量 - @fork_count = Cache::UserProjectForkCountService.call(observed_user) - @platform_fork_count = Cache::PlatformProjectForkCountService.call + @fork_count = @user_result["fork-count"].to_i + @platform_fork_count = @platform_result["fork-count"].to_i # 用户项目关注数 - @project_watchers_count = Cache::UserProjectWatchersCountService.call(observed_user) - @platform_project_watchers_count = Cache::PlatformProjectWatchersCountService.call + @project_watchers_count = @user_result["project-watcher-count"].to_i + @platform_project_watchers_count = @platform_result["project-watcher-count"].to_i # 用户项目点赞数 - @project_praises_count = Cache::UserProjectPraisesCountService.call(observed_user) - @platform_project_praises_count = Cache::PlatformProjectPraisesCountService.call + @project_praises_count = @user_result["project-praise-count"].to_i + @platform_project_praises_count = @platform_result["project-praise-count"].to_i # 用户不同语言项目数量 - @project_languages_count = Cache::UserProjectLanguagesCountService.call(observed_user) - @platform_project_languages_count = Cache::PlatformProjectLanguagesCountService.call + @project_languages_count = JSON.parse(@user_result["project-language"]) + @platform_project_languages_count = JSON.parse(@platform_result["project-language"]) end end end \ No newline at end of file diff --git a/app/jobs/cache_async_reset_job.rb b/app/jobs/cache_async_reset_job.rb index 3b7810918..da3f01168 100644 --- a/app/jobs/cache_async_reset_job.rb +++ b/app/jobs/cache_async_reset_job.rb @@ -1,14 +1,14 @@ class CacheAsyncResetJob < ApplicationJob queue_as :cache - def perform(type, id) + def perform(type, id=nil) case type when "platform_statistic_service" Cache::V2::PlatformStatisticService.new.reset when "project_common_service" Cache::V2::ProjectCommonService.new(id).reset when "user_statistic_service" - Cache::V2::PlatformStatisticService.new(id).reset + Cache::V2::UserStatisticService.new(id).reset end end end \ No newline at end of file diff --git a/app/jobs/cache_async_set_job.rb b/app/jobs/cache_async_set_job.rb index 5a0eb4d83..1c67f91a6 100644 --- a/app/jobs/cache_async_set_job.rb +++ b/app/jobs/cache_async_set_job.rb @@ -1,14 +1,14 @@ class CacheAsyncResetJob < ApplicationJob queue_as :cache - def perform(type, id, params={}) + def perform(type, id=nil, params={}) case type when "platform_statistic_service" Cache::V2::PlatformStatisticService.new(params).call when "project_common_service" Cache::V2::ProjectCommonService.new(id, params).call when "user_statistic_service" - Cache::V2::PlatformStatisticService.new(id, params).call + Cache::V2::UserStatisticService.new(id, params).call end end end \ No newline at end of file diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 0b95d7a58..77e5fe2db 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -17,14 +17,6 @@ class ApplicationRecord < ActiveRecord::Base Rails.env.production? && EduSetting.get('host_name') == 'https://www.educoder.net' end - def reset_user_cache_async_job(user) - ResetUserCacheJob.perform_later(user) - end - - def reset_platform_cache_async_job - ResetPlatformCacheJob.perform_later - end - def self.strip_param(key) key.to_s.strip.presence end diff --git a/app/models/fork_user.rb b/app/models/fork_user.rb index 0936f6bfa..0365af72b 100644 --- a/app/models/fork_user.rb +++ b/app/models/fork_user.rb @@ -24,8 +24,8 @@ class ForkUser < ApplicationRecord after_destroy :reset_cache_data def reset_cache_data - self.reset_platform_cache_async_job - self.reset_user_cache_async_job(self.project.owner) + CacheAsyncResetJob.perform_later("platform_statistic_service") + CacheAsyncResetJob.perform_later("user_statistic_service", self.project&.user_id) end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 826ad3a5b..d195837a7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -79,8 +79,8 @@ class Issue < ApplicationRecord after_destroy :update_closed_issues_count_in_project!, :reset_cache_data def reset_cache_data - self.reset_platform_cache_async_job - self.reset_user_cache_async_job(self.user) + CacheAsyncResetJob.perform_later("platform_statistic_service") + CacheAsyncResetJob.perform_later("user_statistic_service", self.author_id) end def get_assign_user diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 5a9c19164..30d226735 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -1,20 +1,20 @@ -# == Schema Information -# -# Table name: praise_treads -# -# id :integer not null, primary key -# user_id :integer not null -# praise_tread_object_id :integer -# praise_tread_object_type :string(255) -# praise_or_tread :integer default("1") -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# praise_tread (praise_tread_object_id,praise_tread_object_type) -# - +# == Schema Information +# +# Table name: praise_treads +# +# id :integer not null, primary key +# user_id :integer not null +# praise_tread_object_id :integer +# praise_tread_object_type :string(255) +# praise_or_tread :integer default("1") +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# praise_tread (praise_tread_object_id,praise_tread_object_type) +# + class PraiseTread < ApplicationRecord belongs_to :user @@ -26,9 +26,9 @@ class PraiseTread < ApplicationRecord after_destroy :reset_cache_data def reset_cache_data - self.reset_platform_cache_async_job + CacheAsyncResetJob.perform_later("platform_statistic_service") if self.praise_tread_object.is_a?(Project) - self.reset_user_cache_async_job(self.praise_tread_object&.owner) + CacheAsyncResetJob.perform_later("user_statistic_service", self.praise_tread_object&.user_id) end end diff --git a/app/models/project.rb b/app/models/project.rb index 293e6c478..d9933e13d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -151,11 +151,10 @@ class Project < ApplicationRecord 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) + CacheAsyncResetJob.perform_later("user_statistic_service", changes[:user_id].first) end - self.reset_platform_cache_async_job - self.reset_user_cache_async_job(self.owner) + CacheAsyncResetJob.perform_later("platform_statistic_service") + CacheAsyncResetJob.perform_later("user_statistic_service", self.user_id) end def reset_unmember_followed diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index ce0cb04ad..9c6825f27 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -46,8 +46,8 @@ class PullRequest < ApplicationRecord after_destroy :reset_cache_data def reset_cache_data - self.reset_platform_cache_async_job - self.reset_user_cache_async_job(self.user) + CacheAsyncResetJob.perform_later("platform_statistic_service") + CacheAsyncResetJob.perform_later("user_statistic_service", self.user_id) end def fork_project diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 6a8c94fcc..abbcf07bc 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -28,12 +28,12 @@ class Watcher < ApplicationRecord def reset_cache_data if self.watchable.is_a?(User) - self.reset_user_cache_async_job(self.watchable) + CacheAsyncResetJob.perform_later("user_statistic_service", self.watchable_id) end if self.watchable.is_a?(Project) - self.reset_user_cache_async_job(self.watchable&.owner) + CacheAsyncResetJob.perform_later("user_statistic_service", self.watchable&.user_id) end - self.reset_platform_cache_async_job + CacheAsyncResetJob.perform_later("platform_statistic_service") end def send_create_message_to_notice_system