Sha256: 7646f7cfa058893600107f893acc46876a09a9f138599734ac7735d13ff9fde8
Contents?: true
Size: 1.62 KB
Versions: 5
Compression:
Stored size: 1.62 KB
Contents
require 'forwardable' module Wackamole class Log extend ::SingleForwardable def self.logs_cltn() Wackamole::Control.collection( 'logs' ); end def_delegators :logs_cltn, :find, :find_one # Pagination size def self.default_page_size() @page_size ||= 20; end # --------------------------------------------------------------------------- # Fetch all logs matching the given condition def self.paginate( conds, page=1, page_size=default_page_size ) matching = logs_cltn.find( conds ) WillPaginate::Collection.create( page, page_size, matching.count ) do |pager| pager.replace( logs_cltn.find( conds, :sort => [ ['did', 'desc'], ['tid', 'desc'] ], :skip => (page-1)*page_size, :limit => page_size ).to_a ) end end # --------------------------------------------------------------------------- # Makes sure the correct indexes are set def self.ensure_indexes! indexes = logs_cltn.index_information created_count = 0 [:typ, :fid].each do |name| unless indexes.has_key?( "#{name}_1" ) logs_cltn.create_index( name ) created_count += 1 end end unless indexes.key?( "did_-1_tid_-1_type_-1" ) logs_cltn.create_index( [[:did, Mongo::DESCENDING], [:tid, Mongo::DESCENDING], [:type, Mongo::DESCENDING] ] ) end unless indexes.key?( "fid_-1_did_-1" ) logs_cltn.create_index( [[:fid, Mongo::DESCENDING], [:did, Mongo::DESCENDING], [:type, Mongo::DESCENDING] ] ) end created_count end end end
Version data entries
5 entries across 5 versions & 1 rubygems