后台概览增加缓存,增加上周统计数据
This commit is contained in:
parent
9ef255f3b6
commit
f98c044715
|
@ -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
|
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
|
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
|
@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
|
@weekly_active_project_count = Rails.cache.fetch("dashboardscontroller:weekly_active_project_count", expires_in: 10.minutes) do
|
||||||
@month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count
|
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
|
@day_new_project_count = Rails.cache.fetch("dashboardscontroller:day_new_project_count", expires_in: 10.minutes) do
|
||||||
@weekly_new_project_count = Project.where(created_on: current_week).count
|
Project.where(created_on: today).count
|
||||||
@month_new_project_count = Project.where(created_on: current_month).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数
|
# 总的平台Issue数、评论数、PR数、Commit数
|
||||||
@user_count = User.count
|
@user_count = Rails.cache.fetch("dashboardscontroller:platform:user_count", expires_in: 1.days) do
|
||||||
@project_count = Project.count
|
User.count
|
||||||
@organization_count = Organization.count
|
end
|
||||||
@issue_count = Issue.count
|
@project_count = Rails.cache.fetch("dashboardscontroller:platform:project_count", expires_in: 1.days) do
|
||||||
@comment_count = Journal.count
|
Project.count
|
||||||
@pr_count = PullRequest.count
|
end
|
||||||
@commit_count = CommitLog.count
|
@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_name = ["用户数", "项目数", "组织数", "Issue数", "Issue评论数", "PR数", "Commit数"]
|
||||||
@subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"]
|
@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
|
start_date = last_date.date
|
||||||
end_date = Time.now
|
end_date = Time.now
|
||||||
if @access_token.present?
|
if @access_token.present?
|
||||||
@overview_data = tongji_service.overview_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)
|
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
|
end
|
||||||
|
|
||||||
@current_week_statistic = DailyPlatformStatistic.where(date: current_week)
|
@current_week_statistic = DailyPlatformStatistic.where(date: current_week)
|
||||||
|
|
|
@ -15,6 +15,19 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<% if @current_week_statistic.size ==1 && @pre_week_statistic.present? %>
|
||||||
|
<tr class="">
|
||||||
|
<td>上周合计</td>
|
||||||
|
<td><%= @pre_week_statistic.map(&:pv).sum %></td>
|
||||||
|
<td><%= @pre_week_statistic.map(&:visitor).sum %></td>
|
||||||
|
<td><%= @pre_week_statistic.map(&:ip).sum %></td>
|
||||||
|
<td><%= (@pre_week_statistic.map(&:source_through).sum.to_f / 7).round(2) %></td>
|
||||||
|
<td><%= (@pre_week_statistic.map(&:source_link).sum.to_f / 7).round(2) %></td>
|
||||||
|
<td><%= (@pre_week_statistic.map(&:source_search).sum.to_f / 7).round(2) %></td>
|
||||||
|
<td><%= ((@pre_week_statistic.map(&:source_custom) - [nil]).sum.to_f / 7).round(2) %></td>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
<% @current_week_statistic.each_with_index do |week, index| %>
|
<% @current_week_statistic.each_with_index do |week, index| %>
|
||||||
<tr class="">
|
<tr class="">
|
||||||
<td><%= week.date %> </td>
|
<td><%= week.date %> </td>
|
||||||
|
@ -28,13 +41,18 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<!-- <tr class="">-->
|
<tr class="">
|
||||||
<!-- <td><span style="color: #ff8200">合计</span></td>-->
|
<% current_week_size = @current_week_statistic.size %>
|
||||||
<!-- <td><span style="color: #ff8200"><%#= @current_week_statistic.sum(:pv) %></span></td>-->
|
<td><span style="color: #ff8200">本周合计</span></td>
|
||||||
<!-- <td><span style="color: #ff8200"><%#= @current_week_statistic.sum(:visitor) %></span></td>-->
|
<td><span style="color: #ff8200"><%= @current_week_statistic.map(&:pv).sum %></span></td>
|
||||||
<!-- <td><span style="color: #ff8200"><%#= @current_week_statistic.sum(:ip) %></span></td>-->
|
<td><span style="color: #ff8200"><%= @current_week_statistic.map(&:visitor).sum %></span></td>
|
||||||
<!-- </td>-->
|
<td><span style="color: #ff8200"><%= @current_week_statistic.map(&:ip).sum %></span></td>
|
||||||
<!-- </tr>-->
|
<td><span style="color: #ff8200"><%= (@current_week_statistic.map(&:source_through).sum.to_f / current_week_size).round(2) %>%</span></td>
|
||||||
|
<td><span style="color: #ff8200"><%= (@current_week_statistic.map(&:source_link).sum.to_f / current_week_size).round(2) %>%</span></td>
|
||||||
|
<td><span style="color: #ff8200"><%= (@current_week_statistic.map(&:source_search).sum.to_f / current_week_size).round(2) %>%</span></td>
|
||||||
|
<td><span style="color: #ff8200"><%= ((@current_week_statistic.map(&:source_custom) - [nil]).sum.to_f / current_week_size).round(2) %>%</span></td>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue