diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index 321a637..fec9da1 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -4,33 +4,12 @@ class Admin::DashboardsController < ApplicationController layout "basic_back_end" def index - apps = ['bulletin', 'page', 'web_link'] + apps = ['bulletin', 'page_context', 'web_link'] @module_app_contents, @module_app_contents_total = get_module_app_count(apps) @recent_updated = get_recently_updated(apps) @most_visited = get_most_visited(apps) end - def reload_all_content - @module_app_contents, @module_app_contents_total = get_module_app_count('bulletin', 'page_context', 'web_link') - respond_to do |format| - format.js { render 'reload', locals: {div_id: 'all_content'} } - end - end - - def reload_most_visited - @most_visited = get_most_visited('bulletin', 'page_context','page') - respond_to do |format| - format.js { render 'reload', locals: {div_id: 'most_visited'} } - end - end - - def reload_recent_update - @recent_updated = get_recently_updated('bulletin', 'page_context', 'web_link') - respond_to do |format| - format.js { render 'reload', locals: {div_id: 'recent_update'} } - end - end - def get_cpu_usage @usw = Usagewatch render :js => @usw.uw_cpuused.to_s diff --git a/app/helpers/orbit_backend_helper.rb b/app/helpers/orbit_backend_helper.rb index 1a30483..e2cb266 100644 --- a/app/helpers/orbit_backend_helper.rb +++ b/app/helpers/orbit_backend_helper.rb @@ -117,16 +117,24 @@ module OrbitBackendHelper end def get_month_traffic - result = [] - (0..30).each do |i| - visits = Impression.where( created_at: { - '$gte' => Time.now.beginning_of_day-i.days, - '$lte' => Time.now.end_of_day-i.days} - ).distinct(:request_hash).count - result.push([ Time.now.beginning_of_day-i.days, visits]) - end + site = Site.first + if site.month_traffic_cache.blank? or (site.month_traffic_cache['updated_at'] < (Time.now-1.day) rescue true) + site.month_traffic_cache = {} - [:name=> t(:visitors_count),:data=>result] + site.month_traffic_cache['result'] = [] + (1..30).each do |i| + visits = Impression.where( created_at: { + '$gte' => Time.now.beginning_of_day-i.days, + '$lte' => Time.now.end_of_day-i.days} + ).distinct(:request_hash).count + site.month_traffic_cache['result'].push([ Time.now.beginning_of_day-i.days, visits]) + end + + site.month_traffic_cache['updated_at'] = Time.now + site.save + end + + [:name=> t(:visitors_count),:data=>site.month_traffic_cache['result']] end def can_edit_or_delete?(obj) diff --git a/app/models/site.rb b/app/models/site.rb index 6c56469..a35518d 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -33,6 +33,8 @@ class Site field :template, type: String field :site_token field :store_confirmation, type: Boolean, default: false + + field :month_traffic_cache mount_uploader :default_image, ImageUploader mount_uploader :site_logo, ImageUploader diff --git a/app/views/admin/dashboards/_server_loading.erb b/app/views/admin/dashboards/_server_loading.erb index 2f39542..723b43e 100644 --- a/app/views/admin/dashboards/_server_loading.erb +++ b/app/views/admin/dashboards/_server_loading.erb @@ -18,7 +18,7 @@ var Gages = { 'CPU':{ 'container': 'cpu_usage', 'title': 'CPU Usage', 'fn': 'get_cpu_usage', - 'update_interval': 2000, + 'update_interval': 3000, 'initialized': false }, 'Mem':{ diff --git a/app/views/admin/dashboards/_traffic_loading.erb b/app/views/admin/dashboards/_traffic_loading.erb index e7f8a99..8040cfc 100644 --- a/app/views/admin/dashboards/_traffic_loading.erb +++ b/app/views/admin/dashboards/_traffic_loading.erb @@ -12,7 +12,7 @@ legend: 'none', chartArea:{ width: '95%', left: 50, right: 0}, hAxis:{format:'MMM-d',gridlines:{color: '#CCC', count: 31}}, - vAxis:{minValue:-100,viewWindowMode: 'maximized'} + vAxis:{minValue:-20,viewWindowMode: 'maximized'} } %> \ No newline at end of file