From e3d34263e38f1d6c9c34d815890bbbb30793c706 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 8 Jan 2013 12:36:50 +0800 Subject: [PATCH 1/3] Schedule job for tag_cloud --- app/jobs/fetch_time.rb | 15 --------------- app/jobs/update_tag_cloud.rb | 9 +++++++++ app/models/tag.rb | 2 ++ config/resque_schedule.yml | 6 +++--- 4 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 app/jobs/fetch_time.rb create mode 100644 app/jobs/update_tag_cloud.rb diff --git a/app/jobs/fetch_time.rb b/app/jobs/fetch_time.rb deleted file mode 100644 index 5fce3036..00000000 --- a/app/jobs/fetch_time.rb +++ /dev/null @@ -1,15 +0,0 @@ -# require 'open-uri' -# require 'nokogiri' -class FetchTime < Resque::Plugins::RestrictionJob - restrict :per_300 => 10 - - @queue = :low - - def self.perform() -# sleep 10 - doc = Nokogiri::HTML(open('http://www.timeanddate.com/worldclock/city.html?n=241')) - CronMail.time_check(doc.at('#ct').children.first.text).deliver - puts "Mail Sent" - true - end -end diff --git a/app/jobs/update_tag_cloud.rb b/app/jobs/update_tag_cloud.rb new file mode 100644 index 00000000..e0df88d4 --- /dev/null +++ b/app/jobs/update_tag_cloud.rb @@ -0,0 +1,9 @@ +class UpdateTagCloud + @queue = :high + + def self.perform() + Tag.all.each do |tag| + tag.update_attribute(:cloud_view_count, tag.impressionist_count(:created_at.gte => 14.days.ago, :created_at.lte => Time.now)) + end + end +end \ No newline at end of file diff --git a/app/models/tag.rb b/app/models/tag.rb index 758c7899..29cc92aa 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -12,6 +12,8 @@ class Tag field :key field :view_count, :type => Integer, :default => 0 + field :cloud_view_count, :type => Integer, :default => 0 + #field :cloud_amper,:type: Integer,:default=> 0 def self.sorted_for_cloud diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 67d006ed..7c16fc24 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -16,8 +16,8 @@ nccu_daily_backup: args: description: Backup NCCU site -nccu_claender_sync: +update_tag_cloud: cron: 0 0 [0,12] * * * - class: NccuCalendar + class: UpdateTagCloud args: - description: Sync NCCU calendar RSS Feeds \ No newline at end of file + description: UpdateTagCloud \ No newline at end of file From 66dafbb2a01f7f919edbe207b3686cb97b2cf874 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 8 Jan 2013 12:45:15 +0800 Subject: [PATCH 2/3] Put impressionist delayed job in a patch --- patch/impressionist_delayed.diff | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 patch/impressionist_delayed.diff diff --git a/patch/impressionist_delayed.diff b/patch/impressionist_delayed.diff new file mode 100644 index 00000000..8427ce2a --- /dev/null +++ b/patch/impressionist_delayed.diff @@ -0,0 +1,83 @@ +diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb +index a6535c5..a89f60e 100644 +--- a/app/controllers/pages_controller.rb ++++ b/app/controllers/pages_controller.rb +@@ -7,7 +7,7 @@ class PagesController < ApplicationController + @item = Page.find_by_name('home') + + if @item +- impressionist(@item) ++ delayed_impressionist(@item) + render_page + else + render :text => t(:need_home) +@@ -18,7 +18,7 @@ class PagesController < ApplicationController + #begin + @item = Item.first(:conditions => {:path => params[:page_name]}) + if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) +- impressionist(@item) ++ delayed_impressionist(@item) + case @item.class.to_s + when 'Page' + render_page unless save_from_no_lang_for_page +diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb +index e20a0c2..b4aa12b 100644 +--- a/app/helpers/application_helper.rb ++++ b/app/helpers/application_helper.rb +@@ -278,4 +278,8 @@ module ApplicationHelper + end + end + ++ def delayed_impressionist(object) ++ Resque.enqueue_at(1.minute.from_now,DelayedImpressionist,object) ++ end ++ + end +diff --git a/app/jobs/delayed_impressionist.rb b/app/jobs/delayed_impressionist.rb +new file mode 100644 +index 0000000..65a4a6d +--- /dev/null ++++ b/app/jobs/delayed_impressionist.rb +@@ -0,0 +1,7 @@ ++class DelayedImpressionist ++ @queue = :low ++ def self.perform(object) ++ impressionist(object) ++ true ++ end ++end +diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +index 2fe0f71..72fe43b 100644 +--- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb ++++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +@@ -53,7 +53,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController + else + @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num) + end +- impressionist(@tag) if @tag ++ delayed_impressionist(@tag) if @tag + end + + end +@@ -66,7 +66,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController + @bulletin = Bulletin.all.can_display.where(_id: params[:id]).first + if @bulletin and !@bulletin.disable? and !@bulletin.is_rejected + if @bulletin.enabled_for_lang(I18n.locale.to_s) +- impressionist(@bulletin) ++ delayed_impressionist(@bulletin) + get_categorys + else + render :text => "
#{t('sys.can_not_display_due_to_no_context')}
".html_safe +diff --git a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb +index e1e98c7..90a079e 100644 +--- a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb ++++ b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/front_end/page_contexts_controller.rb +@@ -8,7 +8,7 @@ class Panel::PageContent::FrontEnd::PageContextsController < OrbitWidgetControll + def index + # @page_context = PageContext.where("page_id" => params[:page_id], :archived => false) + @page_context = PageContext.first(conditions: { page_id: params[:page_id], :archived => false }) +- impressionist(@page_context) ++ delayed_impressionist(@page_context) + + respond_to do |format| + format.html # index.html.erb From 5b13c53ed99858f69d19bd03fe1a6bb74071a007 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 8 Jan 2013 12:50:28 +0800 Subject: [PATCH 3/3] Ika's changes in default_widget.css --- app/assets/stylesheets/default_widget.css | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/default_widget.css b/app/assets/stylesheets/default_widget.css index bb02a79d..5c15ac02 100644 --- a/app/assets/stylesheets/default_widget.css +++ b/app/assets/stylesheets/default_widget.css @@ -3,7 +3,7 @@ .defulat_widget_typeA{ font: 12px/100% 'open sans',sans-serif; margin:0 0 20px; - width:510px; + } .defulat_widget_tb{ border-collapse:collapse; @@ -19,17 +19,24 @@ .defulat_widget_tb td{ border-bottom: 1px solid #AAAAAA; padding: 10px; + vertical-align: top; white-space: normal; word-wrap: break-word; } - - +.defulat_widget_tb .date{ + display: block; + max-width: 80px; +} +.defulat_widget_tb .category{ + display: block; + max-width: 100px; +} /* 2 */ .defulat_widget_typeB_style2{ font: 12px/100% 'open sans',sans-serif; margin:0 0 20px; - width:510px; + } .defulat_widget_typeB_style2 ul{ @@ -69,7 +76,7 @@ .defulat_widget_typeB_style3{ font: 12px/100% 'open sans',sans-serif; margin:0 0 20px; - width:510px; + } .defulat_widget_typeB_style3 ul{ margin: 0; @@ -114,7 +121,7 @@ .defulat_widget_typeB_style4{ font: 12px/100% 'open sans',sans-serif; margin:0 0 20px; - width:510px; + } .defulat_widget_typeB_style4 ul{ margin: 0; @@ -159,7 +166,6 @@ font: 12px/100% 'open sans',sans-serif; margin: 0 0 20px; position: relative; - width: 510px; } .defulat_widget_typeC ul{ margin: 0 0 0 70px;