Commit d1496a55e665028d4e8bdbcbd0ca66c8260b43ff
Exists in
master
and in
29 other branches
Merge branch 'stable'
Showing
5 changed files
with
19 additions
and
4 deletions
Show diff stats
app/models/communities_block.rb
@@ -49,7 +49,7 @@ class CommunitiesBlock < ProfileListBlock | @@ -49,7 +49,7 @@ class CommunitiesBlock < ProfileListBlock | ||
49 | # FIXME when owner is an environment (i.e. listing communities globally | 49 | # FIXME when owner is an environment (i.e. listing communities globally |
50 | # this can become SLOW) | 50 | # this can become SLOW) |
51 | if block.owner.kind_of?(Environment) | 51 | if block.owner.kind_of?(Environment) |
52 | - block.owner.communities.all(:conditions => {:visible => true}, :limit => block.limit, :order => 'random()').map(&:id) | 52 | + block.owner.communities.all(:conditions => {:visible => true}, :limit => block.limit, :order => Noosfero::SQL.random_function).map(&:id) |
53 | else | 53 | else |
54 | block.owner.communities(:visible => true).map(&:id) | 54 | block.owner.communities(:visible => true).map(&:id) |
55 | end | 55 | end |
app/models/enterprises_block.rb
@@ -46,7 +46,7 @@ class EnterprisesBlock < ProfileListBlock | @@ -46,7 +46,7 @@ class EnterprisesBlock < ProfileListBlock | ||
46 | # FIXME when owner is an environment (i.e. listing enterprises globally | 46 | # FIXME when owner is an environment (i.e. listing enterprises globally |
47 | # this can become SLOW) | 47 | # this can become SLOW) |
48 | if block.owner.kind_of?(Environment) | 48 | if block.owner.kind_of?(Environment) |
49 | - block.owner.enterprises.all(:conditions => {:visible => true}, :limit => block.limit, :order => 'random()').map(&:id) | 49 | + block.owner.enterprises.all(:conditions => {:visible => true}, :limit => block.limit, :order => Noosfero::SQL.random_function).map(&:id) |
50 | else | 50 | else |
51 | block.owner.enterprises.select(&:visible).map(&:id) | 51 | block.owner.enterprises.select(&:visible).map(&:id) |
52 | end | 52 | end |
app/models/people_block.rb
@@ -18,7 +18,7 @@ class PeopleBlock < ProfileListBlock | @@ -18,7 +18,7 @@ class PeopleBlock < ProfileListBlock | ||
18 | 18 | ||
19 | class Finder < ProfileListBlock::Finder | 19 | class Finder < ProfileListBlock::Finder |
20 | def ids | 20 | def ids |
21 | - block.owner.people.visible.all(:limit => block.limit, :order => 'random()').map(&:id) | 21 | + block.owner.people.visible.all(:limit => block.limit, :order => Noosfero::SQL.random_function).map(&:id) |
22 | end | 22 | end |
23 | end | 23 | end |
24 | 24 |
app/models/profile_list_block.rb
@@ -42,7 +42,7 @@ class ProfileListBlock < Block | @@ -42,7 +42,7 @@ class ProfileListBlock < Block | ||
42 | rand(top) | 42 | rand(top) |
43 | end | 43 | end |
44 | def ids | 44 | def ids |
45 | - block.owner.profiles.visible.all(:limit => block.limit, :order => 'random()').map(&:id) | 45 | + block.owner.profiles.visible.all(:limit => block.limit, :order => Noosfero::SQL.random_function).map(&:id) |
46 | end | 46 | end |
47 | end | 47 | end |
48 | 48 |
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +module Noosfero | ||
2 | + module SQL | ||
3 | + class << self | ||
4 | + | ||
5 | + def random_function() | ||
6 | + default = 'random()' | ||
7 | + adapter = ActiveRecord::Base.configurations[Rails.env]['adapter'] | ||
8 | + { | ||
9 | + 'mysql' => 'rand()' | ||
10 | + }[adapter] || default | ||
11 | + end | ||
12 | + | ||
13 | + end | ||
14 | + end | ||
15 | +end |