summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-08-15 23:56:45 +0200
committerhukl <contact@smyck.org>2009-08-15 23:56:45 +0200
commit354ac3e285dc17be6304a85ec5a8385c05d3658c (patch)
tree8f744801d9afa5022abc475109f9b4516ee4bfe7
parent73ff1df7f04809bf0eecd11db66be3c379064473 (diff)
changed the implementation of Page.aggregate once more. Now faster, better shorter with acts_as_taggable_redux
-rw-r--r--app/models/page.rb28
1 files 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
9 9
10 named_scope( 10 named_scope(
11 :drafts, 11 :drafts,
12 :joins => :node, 12 :joins => :node,
13 :include => [:globalize_translations],
13 :conditions => ["nodes.draft_id = pages.id"] 14 :conditions => ["nodes.draft_id = pages.id"]
14 ) 15 )
15 16
16 named_scope( 17 named_scope(
17 :heads, 18 :heads,
18 :joins => :node, 19 :joins => :node,
20 :include => [:globalize_translations],
19 :conditions => ["nodes.head_id = pages.id"] 21 :conditions => ["nodes.head_id = pages.id"]
20 ) 22 )
21 23
@@ -56,28 +58,14 @@ class Page < ActiveRecord::Base
56 58
57 options = defaults.merge options 59 options = defaults.merge options
58 60
59 pages = Page.heads.paged_find_tagged_with( 61 Page.heads.find_tagged_with(
60 options[:tags].gsub(/\s/, ", "), 62 options[:tags].gsub(/\s/, ", "),
61 :page => page, 63 :match => :all,
62 :per_page => 23,
63 :include => [:globalize_translations],
64 :order => "#{options[:order_by]} #{options[:order_direction]}" 64 :order => "#{options[:order_by]} #{options[:order_direction]}"
65 ) 65 ).paginate(:page=>page, :per_page => options[:limit])
66 66
67 end 67 end
68 68
69 def self.paged_find_tagged_with(tags, args = {})
70 if tags.blank?
71 paginate args
72 else
73 options = find_options_for_find_tagged_with(tags, :match_all => true)
74 options.merge!(args)
75 # FIXME The select {} looks really bad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
76 # The default count query generated by paginate includes COUNT(DISTINCT Posts.*) which errors, at least on mysql
77 # Below we override the default select statement used to perform the count so that it becomes COUNT(DISTINCT Posts.id)
78 paginate(options.merge(:count => { :select => options[:select].gsub('*', 'id') }))
79 end
80 end
81 69
82 def self.custom_templates 70 def self.custom_templates
83 files = Dir.entries(FULL_PUBLIC_TEMPLATE_PATH).select do |x| 71 files = Dir.entries(FULL_PUBLIC_TEMPLATE_PATH).select do |x|