diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 2d1320fc6..7898fcd57 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -1,9 +1,13 @@ class Admins::DashboardsController < Admins::BaseController def index + # 查询优化 + week_greater_id = CommitLog.where(created_at: current_week).limit(1)[0]&.id + #月份统计还需要优化 + month_greater_id = CommitLog.where(created_at: current_month).limit(1)[0]&.id # 用户活跃数 day_user_ids = CommitLog.where(created_at: today).pluck(:user_id).uniq - weekly_user_ids = CommitLog.where(created_at: current_week).pluck(:user_id).uniq - month_user_ids = CommitLog.where(created_at: current_month).pluck(:user_id).uniq + weekly_user_ids = CommitLog.where(created_at: current_week).where("id>= ?", week_greater_id).distinct.pluck(:user_id) + month_user_ids = CommitLog.where(created_at: current_month).where("id>= ?", month_greater_id).distinct.pluck(:user_id) @active_user_count = User.where(last_login_on: today).or(User.where(id: day_user_ids)).count @weekly_active_user_count = User.where(last_login_on: current_week).or(User.where(id: weekly_user_ids)).count @month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count @@ -18,10 +22,7 @@ class Admins::DashboardsController < Admins::BaseController # 活跃项目数 day_project_ids = (CommitLog.where(created_at: today).pluck(:project_id).uniq + Issue.where(created_on: today).pluck(:project_id).uniq).uniq - week_greater_id = CommitLog.where(created_at: current_week).limit(1)[0]&.id - weekly_project_ids = (CommitLog.where(created_at: current_week).where("id>= ?", week_greater_id).distinct.pluck(:project_id) + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq - #月份统计还需要优化 - month_greater_id = CommitLog.where(created_at: current_month).limit(1)[0]&.id + weekly_project_ids = (CommitLog.where(created_at: current_week).where("id>= ?", week_greater_id).distinct.pluck(:project_id) + Issue.where(created_on: current_week).pluck(:project_id).uniq).uni month_project_ids = (CommitLog.where(created_at: current_month).where("id>= ?", month_greater_id).distinct.pluck(:project_id) + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq @day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count @weekly_active_project_count = Rails.cache.fetch("dashboardscontroller:weekly_active_project_count", expires_in: 10.minutes) do