Fix stream query for postgres, shouldn't break mysql
This commit is contained in:
parent
9309456c41
commit
7c454b7d15
3 changed files with 21 additions and 4 deletions
3
Gemfile
3
Gemfile
|
|
@ -1,6 +1,7 @@
|
||||||
source 'http://rubygems.org'
|
source 'http://rubygems.org'
|
||||||
|
|
||||||
gem 'mysql2', '0.2.6'
|
#gem 'mysql2', '0.2.6'
|
||||||
|
gem 'pg'
|
||||||
gem 'rails', '3.0.3'
|
gem 'rails', '3.0.3'
|
||||||
gem 'foreigner', '0.9.1'
|
gem 'foreigner', '0.9.1'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,6 @@ GEM
|
||||||
multi_json (1.0.3)
|
multi_json (1.0.3)
|
||||||
multi_xml (0.2.2)
|
multi_xml (0.2.2)
|
||||||
multipart-post (1.1.2)
|
multipart-post (1.1.2)
|
||||||
mysql2 (0.2.6)
|
|
||||||
net-ldap (0.2.2)
|
net-ldap (0.2.2)
|
||||||
net-scp (1.0.4)
|
net-scp (1.0.4)
|
||||||
net-ssh (>= 1.99.1)
|
net-ssh (>= 1.99.1)
|
||||||
|
|
@ -283,6 +282,7 @@ GEM
|
||||||
oa-openid (= 0.2.6)
|
oa-openid (= 0.2.6)
|
||||||
open4 (1.0.1)
|
open4 (1.0.1)
|
||||||
orm_adapter (0.0.5)
|
orm_adapter (0.0.5)
|
||||||
|
pg (0.11.0)
|
||||||
polyglot (0.3.1)
|
polyglot (0.3.1)
|
||||||
pyu-ruby-sasl (0.0.3.3)
|
pyu-ruby-sasl (0.0.3.3)
|
||||||
rack (1.2.3)
|
rack (1.2.3)
|
||||||
|
|
@ -430,11 +430,11 @@ DEPENDENCIES
|
||||||
linecache (= 0.43)
|
linecache (= 0.43)
|
||||||
mini_magick (= 3.2)
|
mini_magick (= 3.2)
|
||||||
mongrel
|
mongrel
|
||||||
mysql2 (= 0.2.6)
|
|
||||||
newrelic_rpm
|
newrelic_rpm
|
||||||
nokogiri
|
nokogiri
|
||||||
ohai (= 0.5.8)
|
ohai (= 0.5.8)
|
||||||
omniauth (= 0.2.6)
|
omniauth (= 0.2.6)
|
||||||
|
pg
|
||||||
rails (= 3.0.3)
|
rails (= 3.0.3)
|
||||||
rcov
|
rcov
|
||||||
resque (= 1.10.0)
|
resque (= 1.10.0)
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,27 @@ module Diaspora
|
||||||
posts_from_self = posts_from_self.select(select_clause).limit(opts[:limit]).order(order_with_table).where(Post.arel_table[order_field].lt(opts[:max_time]))
|
posts_from_self = posts_from_self.select(select_clause).limit(opts[:limit]).order(order_with_table).where(Post.arel_table[order_field].lt(opts[:max_time]))
|
||||||
|
|
||||||
all_posts = "(#{posts_from_others.to_sql}) UNION ALL (#{posts_from_self.to_sql}) ORDER BY #{opts[:order]} LIMIT #{opts[:limit]}"
|
all_posts = "(#{posts_from_others.to_sql}) UNION ALL (#{posts_from_self.to_sql}) ORDER BY #{opts[:order]} LIMIT #{opts[:limit]}"
|
||||||
post_ids = Post.connection.execute(all_posts).map{|r| r.first}
|
|
||||||
|
post_ids = Post.connection.execute(all_posts).map {|post| id_for(post) }
|
||||||
|
|
||||||
Post.where(:id => post_ids).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table)
|
Post.where(:id => post_ids).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Determine, cache, and execute the method call needed to extract the id from a raw result row.
|
||||||
|
# Returns row["id"] for PostgreSQL
|
||||||
|
# Returns row.first for everything else (MYSQL)
|
||||||
|
#
|
||||||
|
# @param row The row to get the id from.
|
||||||
|
# @return The id of the database row passed in.
|
||||||
|
def id_for row
|
||||||
|
@@id_method_for_row ||= if Post.connection.class == ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
||||||
|
[:[], "id"]
|
||||||
|
else
|
||||||
|
:first
|
||||||
|
end
|
||||||
|
row.send(*@@id_method_for_row)
|
||||||
|
end
|
||||||
|
|
||||||
def visible_photos(opts = {})
|
def visible_photos(opts = {})
|
||||||
visible_posts(opts.merge(:type => 'Photo'))
|
visible_posts(opts.merge(:type => 'Photo'))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue