From 354ac3e285dc17be6304a85ec5a8385c05d3658c Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 15 Aug 2009 23:56:45 +0200 Subject: changed the implementation of Page.aggregate once more. Now faster, better shorter with acts_as_taggable_redux --- app/models/page.rb | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index ef92d4e..30f5ec2 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -9,13 +9,15 @@ class Page < ActiveRecord::Base named_scope( :drafts, - :joins => :node, + :joins => :node, + :include => [:globalize_translations], :conditions => ["nodes.draft_id = pages.id"] ) named_scope( :heads, :joins => :node, + :include => [:globalize_translations], :conditions => ["nodes.head_id = pages.id"] ) @@ -56,28 +58,14 @@ class Page < ActiveRecord::Base options = defaults.merge options - pages = Page.heads.paged_find_tagged_with( - options[:tags].gsub(/\s/, ", "), - :page => page, - :per_page => 23, - :include => [:globalize_translations], + Page.heads.find_tagged_with( + options[:tags].gsub(/\s/, ", "), + :match => :all, :order => "#{options[:order_by]} #{options[:order_direction]}" - ) + ).paginate(:page=>page, :per_page => options[:limit]) end - - def self.paged_find_tagged_with(tags, args = {}) - if tags.blank? - paginate args - else - options = find_options_for_find_tagged_with(tags, :match_all => true) - options.merge!(args) - # FIXME The select {} looks really bad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - # The default count query generated by paginate includes COUNT(DISTINCT Posts.*) which errors, at least on mysql - # Below we override the default select statement used to perform the count so that it becomes COUNT(DISTINCT Posts.id) - paginate(options.merge(:count => { :select => options[:select].gsub('*', 'id') })) - end - end + def self.custom_templates files = Dir.entries(FULL_PUBLIC_TEMPLATE_PATH).select do |x| -- cgit v1.3