From 9745d099906ce253a69115789e108fc83be43926 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 5 Mar 2015 19:48:38 +0800 Subject: [PATCH] added indexing in intializer --- app/models/bulletin.rb | 7 +++++++ app/views/admin/announcements/_form.html.erb | 13 ++++++------- lib/announcement/engine.rb | 6 ++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 601146a..8bfd6ac 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -20,6 +20,7 @@ class Bulletin field :rss2_sn field :approved, :type => Boolean, :default => false field :is_preview, :type => Boolean, :default => false + field :expirable_created_at, type: DateTime field :email_id field :email_sent, :type => Boolean, :default => false @@ -41,6 +42,12 @@ class Bulletin scope :can_display, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])} scope :is_approved, ->{where(:approved => true)} + before_create :set_expire + def set_expire + self.expirable_created_at = Time.now if self.is_preview + return true + end + def update_user User.find(update_user_id) rescue nil end diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index 0f64704..38ead79 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -23,7 +23,6 @@
  • <%= t(:image) %>
  • <%= t('announcement.email_reminder')%>
  • -
    @@ -42,14 +41,14 @@
    - <%= f.datetime_picker :postdate, :no_label => true %> + <%= f.datetime_picker :postdate, :no_label => true, :new_record => @bulletin.new_record? %>
    - <%= f.datetime_picker :deadline, :no_label => true %> + <%= f.datetime_picker :deadline, :no_label => true, :new_record => @bulletin.new_record? %>
    @@ -389,10 +388,10 @@ }); var slug = data.split('/')[(data.split('/').length-1)]; - $('#preview-iframe').on('load', function(){ - $.get('/admin/announcement/destroy_preview/'+slug,function(data){ - }); - }); + // $('#preview-iframe').on('load', function(){ + // $.get('/admin/announcement/destroy_preview/'+slug,function(data){ + // }); + // }); }); $('.main-forms input[name="_method"]').val(method); return false; diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index 174c9ad..9c52373 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -1,3 +1,4 @@ +require "yaml" module Announcement class Engine < ::Rails::Engine initializer "announcement" do @@ -45,6 +46,11 @@ module Announcement end end + temp = YAML.load_file(File.join(Rails.root,"config","mongoid.yml")) + dbsettings = temp["production"]["sessions"]["default"] + s = Moped::Session.new(dbsettings["hosts"]) + s.use dbsettings["database"] + s[:bulletins].indexes.create({expirable_created_at: 1},{ expireAfterSeconds: 180 }) end end end \ No newline at end of file