Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

secondary sorting

  • Loading branch information...
commit 8c191329042d07758d61216844ae080f0f171729 1 parent 9e50d0e
@Raven24 authored
View
13 lib/diaspora/shareable.rb
@@ -33,10 +33,15 @@ def self.owned_or_visible_by_user(user)
select("DISTINCT #{self.table_name}.*")
end
- def self.for_visible_shareable_sql(max_time, order, limit = 15, types = Stream::Base::TYPES_OF_POST_IN_STREAM)
- by_max_time(max_time, order).
- where(:type => types).
- limit(limit)
+ def self.for_visible_shareable_sql(max_time, order_cls, limit = 15, types = Stream::Base::TYPES_OF_POST_IN_STREAM)
+ order_cls = {:primary=>order_cls} unless order_cls.is_a? Hash
+ return_sql = by_max_time(max_time, order_cls[:primary]).
+ where(:type => types).
+ limit(limit)
+
+ return_sql = return_sql.order("#{order_cls[:secondary]} desc") if order_cls.key?(:secondary)
+
+ return_sql
end
def self.by_max_time(max_time, order='created_at')
View
2  lib/evil_query.rb
@@ -57,7 +57,7 @@ def make_relation!
end
def aspects_post_ids!
- @user.visible_shareable_ids(Post, :limit => 15, :order => "#{@order} DESC", :max_time => @max_time, :all_aspects? => true, :by_members_of => @user.aspect_ids)
+ @user.visible_shareable_ids(Post, :limit => 15, :order => "#{@order[:primary]} DESC", :max_time => @max_time, :all_aspects? => true, :by_members_of => @user.aspect_ids)
end
def followed_tags_posts!
View
4 lib/stream/activity.rb
@@ -4,7 +4,7 @@ def link(opts={})
end
def order
- "interacted_at"
+ {:primary => "interacted_at", :secondary => "#{Participation.table_name}.id"}
end
def title
@@ -15,4 +15,4 @@ def title
def posts
@posts ||= EvilQuery::Participation.new(user).posts
end
-end
+end
View
2  lib/stream/aspect.rb
@@ -41,7 +41,7 @@ def posts
@posts ||= user.visible_shareables(Post, :all_aspects? => for_all_aspects?,
:by_members_of => aspect_ids,
:type => TYPES_OF_POST_IN_STREAM,
- :order => "#{order} DESC",
+ :order => "#{order[:primary]} DESC",
:max_time => max_time
)
end
View
5 lib/stream/base.rb
@@ -92,8 +92,9 @@ def max_time=(time_string)
end
def order=(order_string)
- @order = order_string
- @order ||= 'created_at'
+ @order ||= {}
+ @order[:primary] = order_string
+ @order[:primary] ||= 'created_at'
end
protected
View
4 lib/stream/multi.rb
@@ -15,6 +15,10 @@ def contacts_title
I18n.t('streams.multi.contacts_title')
end
+ def order
+ {:primary => "created_at", :secondary => "#{Post.table_name}.id"}
+ end
+
def posts
@posts ||= ::EvilQuery::MultiStream.new(user, order, max_time, include_community_spotlight?).make_relation!
end
Please sign in to comment.
Something went wrong with that request. Please try again.