fix order with two posts with the same timestamp for all streams
This commit is contained in:
parent
7583568be8
commit
e3d1f0fd16
4 changed files with 18 additions and 17 deletions
|
|
@ -14,7 +14,7 @@ module User::Querying
|
||||||
opts = prep_opts(klass, opts)
|
opts = prep_opts(klass, opts)
|
||||||
shareable_ids = visible_shareable_ids(klass, opts)
|
shareable_ids = visible_shareable_ids(klass, opts)
|
||||||
klass.where(id: shareable_ids).select("DISTINCT #{klass.table_name}.*")
|
klass.where(id: shareable_ids).select("DISTINCT #{klass.table_name}.*")
|
||||||
.limit(opts[:limit]).order(opts[:order_with_table]).order(klass.table_name + ".id DESC")
|
.limit(opts[:limit]).order(opts[:order_with_table])
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible_shareable_ids(klass, opts={})
|
def visible_shareable_ids(klass, opts={})
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.for_visible_shareable_sql(max_time, order, limit=15, types=Stream::Base::TYPES_OF_POST_IN_STREAM)
|
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)
|
by_max_time(max_time, order).order(table_name + ".id DESC").where(type: types).limit(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.by_max_time(max_time, order="created_at")
|
def self.by_max_time(max_time, order="created_at")
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,22 @@ describe Post, :type => :model do
|
||||||
Post.for_visible_shareable_sql(Time.now + 1, "created_at")
|
Post.for_visible_shareable_sql(Time.now + 1, "created_at")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with two posts with the same timestamp" do
|
||||||
|
before do
|
||||||
|
aspect_id = alice.aspects.where(name: "generic").first.id
|
||||||
|
Timecop.freeze Time.now do
|
||||||
|
alice.post(:status_message, text: "first", to: aspect_id)
|
||||||
|
alice.post(:status_message, text: "second", to: aspect_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns them in reverse creation order" do
|
||||||
|
posts = Post.for_visible_shareable_sql(Time.now + 1, "created_at")
|
||||||
|
expect(posts.first.text).to eq("second")
|
||||||
|
expect(posts.at(1).text).to eq("first")
|
||||||
|
expect(posts.last.text).to eq("alice - 5")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -113,21 +113,6 @@ describe User::Querying, :type => :model do
|
||||||
expect(bob.visible_shareables(Post).count(:all)).to eq(0)
|
expect(bob.visible_shareables(Post).count(:all)).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with two posts with the same timestamp' do
|
|
||||||
before do
|
|
||||||
aspect_id = alice.aspects.where(:name => "generic").first.id
|
|
||||||
Timecop.freeze Time.now do
|
|
||||||
alice.post :status_message, :text => "first", :to => aspect_id
|
|
||||||
alice.post :status_message, :text => "second", :to => aspect_id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns them in reverse creation order" do
|
|
||||||
expect(bob.visible_shareables(Post).first.text).to eq("second")
|
|
||||||
expect(bob.visible_shareables(Post).last.text).to eq("first")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with many posts' do
|
context 'with many posts' do
|
||||||
before do
|
before do
|
||||||
time_interval = 1000
|
time_interval = 1000
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue