From e4faee134a726dfaf2c798e07955ddddb2bbd278 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 22 Jan 2024 11:39:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E7=99=BE=E5=BA=A6?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=83=A8=E5=88=86=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E6=8C=89=E5=A4=A9=E5=AD=98=E5=82=A8,refresh=5Faccess=5Ftoken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/baidu/tongji_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/baidu/tongji_service.rb b/app/services/baidu/tongji_service.rb index 8a611cd0f..a2a4f28fc 100644 --- a/app/services/baidu/tongji_service.rb +++ b/app/services/baidu/tongji_service.rb @@ -147,7 +147,7 @@ module Baidu def access_token access_token = Rails.cache.read("baidu_tongji_auth/access_token") - if access_token.blank? + if access_token.blank? && refresh_token.present? refresh_access_token access_token = Rails.cache.read("baidu_tongji_auth/access_token") end From 9ef255f3b638568e2f9552c1318dc8523029d441 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 22 Jan 2024 12:07:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E7=99=BE=E5=BA=A6?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=83=A8=E5=88=86=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=80=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/dashboards/index.html.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index 35593f169..5441a1802 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -1,6 +1,8 @@ <% define_admin_breadcrumbs do %> <% add_admin_breadcrumb('概览', admins_path) %> <% end %> + +<% cache "/admin/dashboards/#{Time.now.strftime('%Y-%m-%d')}", :expires_in => 1.days do %>
@@ -30,6 +32,7 @@
+<%end %>
From f98c0447158699f1cce390d3c42ac2f4f7df3b3e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 22 Jan 2024 12:57:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=A6=82=E8=A7=88?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E5=91=A8=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/dashboards_controller.rb | 57 ++++++++++++++----- .../admins/dashboards/_baidu_tongji.html.erb | 32 ++++++++--- 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 1e13621e9..6940ed1cf 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -21,25 +21,49 @@ class Admins::DashboardsController < Admins::BaseController weekly_project_ids = (CommitLog.where(created_at: current_week).pluck(:project_id).uniq + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq month_project_ids = (CommitLog.where(created_at: current_month).pluck(:project_id).uniq + 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 = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count - @month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count - + @weekly_active_project_count = Rails.cache.fetch("dashboardscontroller:weekly_active_project_count", expires_in: 10.minutes) do + Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count + end + @month_active_project_count = Rails.cache.fetch("dashboardscontroller:month_active_project_count", expires_in: 1.hours) do + Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count + end # 新增项目数 - @day_new_project_count = Project.where(created_on: today).count - @weekly_new_project_count = Project.where(created_on: current_week).count - @month_new_project_count = Project.where(created_on: current_month).count + @day_new_project_count = Rails.cache.fetch("dashboardscontroller:day_new_project_count", expires_in: 10.minutes) do + Project.where(created_on: today).count + end + @weekly_new_project_count = Rails.cache.fetch("dashboardscontroller:weekly_new_project_count", expires_in: 10.minutes) do + Project.where(created_on: current_week).count + end + @month_new_project_count = Rails.cache.fetch("dashboardscontroller:month_new_project_count", expires_in: 1.hours) do + Project.where(created_on: current_month).count + end + # 总的平台用户数 # 总的平台项目数 # 总的平台组织数 # 总的平台Issue数、评论数、PR数、Commit数 - @user_count = User.count - @project_count = Project.count - @organization_count = Organization.count - @issue_count = Issue.count - @comment_count = Journal.count - @pr_count = PullRequest.count - @commit_count = CommitLog.count + @user_count = Rails.cache.fetch("dashboardscontroller:platform:user_count", expires_in: 1.days) do + User.count + end + @project_count = Rails.cache.fetch("dashboardscontroller:platform:project_count", expires_in: 1.days) do + Project.count + end + @organization_count = Rails.cache.fetch("dashboardscontroller:platform:organization_count", expires_in: 1.days) do + Organization.count + end + @issue_count = Rails.cache.fetch("dashboardscontroller:platform:issue_count", expires_in: 1.days) do + Issue.count + end + @comment_count = Rails.cache.fetch("dashboardscontroller:platform:comment_count", expires_in: 1.days) do + Journal.count + end + @pr_count = Rails.cache.fetch("dashboardscontroller:platform:pr_count", expires_in: 1.days) do + PullRequest.count + end + @commit_count = Rails.cache.fetch("dashboardscontroller:platform:commit_count", expires_in: 1.days) do + CommitLog.count + end @subject_name = ["用户数", "项目数", "组织数", "Issue数", "Issue评论数", "PR数", "Commit数"] @subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"] @@ -54,8 +78,11 @@ class Admins::DashboardsController < Admins::BaseController start_date = last_date.date end_date = Time.now if @access_token.present? - @overview_data = tongji_service.overview_batch_add(start_date, end_date) - tongji_service.source_from_batch_add(start_date, end_date) + @overview_data = Rails.cache.fetch("dashboardscontroller:baidu_tongji:overview_data", expires_in: 10.minutes) do + tongji_service.source_from_batch_add(start_date, end_date) + @overview_data = tongji_service.overview_batch_add(start_date, end_date) + @overview_data + end end @current_week_statistic = DailyPlatformStatistic.where(date: current_week) diff --git a/app/views/admins/dashboards/_baidu_tongji.html.erb b/app/views/admins/dashboards/_baidu_tongji.html.erb index c59e1acad..ca697332d 100644 --- a/app/views/admins/dashboards/_baidu_tongji.html.erb +++ b/app/views/admins/dashboards/_baidu_tongji.html.erb @@ -15,6 +15,19 @@ + <% if @current_week_statistic.size ==1 && @pre_week_statistic.present? %> + + + + + + + + + + + + <% end %> <% @current_week_statistic.each_with_index do |week, index| %> @@ -28,13 +41,18 @@ <% end %> - - - - - - - + + <% current_week_size = @current_week_statistic.size %> + + + + + + + + + +
上周合计<%= @pre_week_statistic.map(&:pv).sum %><%= @pre_week_statistic.map(&:visitor).sum %><%= @pre_week_statistic.map(&:ip).sum %><%= (@pre_week_statistic.map(&:source_through).sum.to_f / 7).round(2) %><%= (@pre_week_statistic.map(&:source_link).sum.to_f / 7).round(2) %><%= (@pre_week_statistic.map(&:source_search).sum.to_f / 7).round(2) %><%= ((@pre_week_statistic.map(&:source_custom) - [nil]).sum.to_f / 7).round(2) %>
<%= week.date %>
本周合计<%= @current_week_statistic.map(&:pv).sum %><%= @current_week_statistic.map(&:visitor).sum %><%= @current_week_statistic.map(&:ip).sum %><%= (@current_week_statistic.map(&:source_through).sum.to_f / current_week_size).round(2) %>%<%= (@current_week_statistic.map(&:source_link).sum.to_f / current_week_size).round(2) %>%<%= (@current_week_statistic.map(&:source_search).sum.to_f / current_week_size).round(2) %>%<%= ((@current_week_statistic.map(&:source_custom) - [nil]).sum.to_f / current_week_size).round(2) %>%