From 1ed41b93d88c840ebf81b303b183de4331ad0ae0 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 6 Mar 2024 15:30:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BC=80=E5=90=AF=E7=99=BE?= =?UTF-8?q?=E5=BA=A6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/dashboards_controller.rb | 34 +++++++++---------- app/views/admins/dashboards/index.html.erb | 2 ++ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/admins/dashboards_controller.rb b/app/controllers/admins/dashboards_controller.rb index 6940ed1cf..37b69dc0d 100644 --- a/app/controllers/admins/dashboards_controller.rb +++ b/app/controllers/admins/dashboards_controller.rb @@ -69,26 +69,26 @@ class Admins::DashboardsController < Admins::BaseController @subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"] @subject_data = [@user_count, @project_count, @organization_count, @issue_count, @comment_count, @pr_count, @commit_count] - - tongji_service = Baidu::TongjiService.new - @access_token = tongji_service.access_token - Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}" - # @overview_data = tongji_service.api_overview - last_date = DailyPlatformStatistic.order(:date).last - start_date = last_date.date - end_date = Time.now - if @access_token.present? - @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 + if EduSetting.get("open_baidu_tongji").to_s == "true" + tongji_service = Baidu::TongjiService.new + @access_token = tongji_service.access_token + Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}" + # @overview_data = tongji_service.api_overview + last_date = DailyPlatformStatistic.order(:date).last || Time.now + start_date = last_date.date + end_date = Time.now + if @access_token.present? + @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) + @pre_week_statistic = DailyPlatformStatistic.where(date: pre_week) end - @current_week_statistic = DailyPlatformStatistic.where(date: current_week) - @pre_week_statistic = DailyPlatformStatistic.where(date: pre_week) - - end diff --git a/app/views/admins/dashboards/index.html.erb b/app/views/admins/dashboards/index.html.erb index 5441a1802..a55ef55e4 100644 --- a/app/views/admins/dashboards/index.html.erb +++ b/app/views/admins/dashboards/index.html.erb @@ -85,7 +85,9 @@ + <% if EduSetting.get("open_baidu_tongji").to_s == "true" %> <%= render partial: 'admins/dashboards/baidu_tongji' %> + <% end %>
\ No newline at end of file