added indexing in intializer

This commit is contained in:
Harry Bomrah 2015-03-05 19:48:38 +08:00
parent 2921aa62d4
commit 9745d09990
3 changed files with 19 additions and 7 deletions

View File

@ -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

View File

@ -23,7 +23,6 @@
<li><a href="#imageupload" data-toggle="tab"><%= t(:image) %></a></li>
<li><a href="#mail-group" data-toggle="tab"><%= t('announcement.email_reminder')%></a></li>
</ul>
<!-- Module -->
<div class="tab-content module-area">
@ -42,14 +41,14 @@
<div class="control-group">
<label class="control-label muted"><%= t(:start_date) %></label>
<div class="controls">
<%= f.datetime_picker :postdate, :no_label => true %>
<%= f.datetime_picker :postdate, :no_label => true, :new_record => @bulletin.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t(:end_date) %></label>
<div class="controls">
<%= f.datetime_picker :deadline, :no_label => true %>
<%= f.datetime_picker :deadline, :no_label => true, :new_record => @bulletin.new_record? %>
</div>
</div>
@ -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;

View File

@ -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