Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ 3.6.14, ! terminate_early

  • Loading branch information...
commit 2e628bd0a5481ab0758a79b44c6f5cd9f01a8bcb 1 parent 6af3b12
@floere authored
View
4 history.textile
@@ -1,5 +1,9 @@
h2. Upcoming Version
+h2. Version 3.6.14
+
+* hanke: (server) Fix for terminate_early with offsets in 3.6.12 (thanks niko!).
+
h2. Version 3.6.13
* hanke: (server) Fix for exact first matching (thanks geelen!).
View
3  server/lib/picky/query/allocations.rb
@@ -72,7 +72,6 @@ def ids amount = 20
# Note: It's possible that no ids are returned by an allocation, but a count. (In case of an offset)
#
def process! amount, offset = 0, terminate_early = nil
- current_offset = 0
each do |allocation|
ids = allocation.process! amount, offset
if ids.empty?
@@ -82,7 +81,7 @@ def process! amount, offset = 0, terminate_early = nil
offset = 0 # we have already passed the offset
end
if terminate_early
- break if terminate_early < 0 && offset <= 0
+ break if terminate_early <= 0 && amount <= 0
terminate_early -= 1
end
end
View
19 server/spec/functional/terminate_early_spec.rb
@@ -23,6 +23,9 @@
try = Picky::Search.new index
try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
+ try = Picky::Search.new index
+ try.search('hello', 30).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
+
try = Picky::Search.new index do
terminate_early
end
@@ -37,21 +40,33 @@
terminate_early with_extra_allocations: 0
end
try.search('hello', 9).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4]
+ try.search('hello', 9, 4).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6]
+ try.search('hello', 9, 7).ids.should == [5, 4, 3, 2, 1, 6, 5, 4, 3]
+ try.search('hello', 9, 10).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6]
+ try.search('hello', 9, 13).ids.should == [5, 4, 3, 2, 1, 6, 5, 4, 3]
+ try.search('hello', 9, 16).ids.should == [2, 1, 6, 5, 4, 3, 2, 1]
+ try.search('hello', 9, 19).ids.should == [5, 4, 3, 2, 1]
+ try.search('hello', 9, 22).ids.should == [2, 1]
+ try.search('hello', 9, 25).ids.should == []
try = Picky::Search.new index do
terminate_early 0
end
- try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
+ try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
try = Picky::Search.new index do
terminate_early with_extra_allocations: 0
end
- try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
+ try.search('hello').ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5]
try = Picky::Search.new index do
terminate_early 2
end
try.search('hello', 13).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6]
+ try.search('hello', 13, 4).ids.should == [2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2]
+ try.search('hello', 13, 8).ids.should == [4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 6, 5, 4]
+ try.search('hello', 13, 12).ids.should == [6, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]
+ try.search('hello', 13, 16).ids.should == [2, 1, 6, 5, 4, 3, 2, 1]
try = Picky::Search.new index do
terminate_early with_extra_allocations: 2
View
109 server/spec/lib/query/allocations_spec.rb
@@ -81,20 +81,20 @@
describe 'process!' do
before(:each) do
- @allocation1 = stub :allocation1, :process! => [], :count => 4 #, ids: [1, 2, 3, 4]
- @allocation2 = stub :allocation2, :process! => [], :count => 3 #, ids: [5, 6, 7]
- @allocation3 = stub :allocation3, :process! => [], :count => 2 #, ids: [8, 9]
+ @allocation1 = stub :allocation1, :count => 4 #, ids: [1, 2, 3, 4]
+ @allocation2 = stub :allocation2, :count => 3 #, ids: [5, 6, 7]
+ @allocation3 = stub :allocation3, :count => 2 #, ids: [8, 9]
@allocations = described_class.new [@allocation1, @allocation2, @allocation3]
end
describe 'lazy evaluation' do
context 'small amount' do
before(:each) do
- @amount = 3
+ @amount = 5
@offset = 1
end
it 'should call the process! method right' do
- @allocation1.should_receive(:process!).once.with(3,1).and_return [1, 2, 3]
- @allocation2.should_receive(:process!).once.with(0,0).and_return [] # TODO Actually ok?
+ @allocation1.should_receive(:process!).once.with(5,1).and_return [2, 3, 4]
+ @allocation2.should_receive(:process!).once.with(2,0).and_return [5, 6]
@allocation3.should_receive(:process!).never
@allocations.process! @amount, @offset, 0
@@ -107,12 +107,103 @@
end
it 'should call the process! method right' do
@allocation1.should_receive(:process!).once.with(1,0).and_return [1]
- @allocation2.should_receive(:process!).once.with(0,0).and_return [] # TODO Actually ok?
+ @allocation2.should_receive(:process!).never
@allocation3.should_receive(:process!).never
@allocations.process! @amount, @offset, 0
end
end
+ context 'small amount and early 1' do
+ before(:each) do
+ @amount = 5
+ @offset = 1
+ end
+ it 'should call the process! method right' do
+ @allocation1.should_receive(:process!).once.with(5,1).and_return [2, 3, 4]
+ @allocation2.should_receive(:process!).once.with(2,0).and_return [5, 6]
+ @allocation3.should_receive(:process!).never
+
+ @allocations.process! @amount, @offset, 1
+ end
+ end
+ context 'larger amount and early 1' do
+ before(:each) do
+ @amount = 1
+ @offset = 0
+ end
+ it 'should call the process! method right' do
+ @allocation1.should_receive(:process!).once.with(1,0).and_return [1]
+ @allocation2.should_receive(:process!).once.with(0,0).and_return []
+ @allocation3.should_receive(:process!).never
+
+ @allocations.process! @amount, @offset, 1
+ end
+ end
+ context 'larger amount and early 0' do
+ before(:each) do
+ @amount = 4
+ @offset = 0
+ end
+ it 'should call the process! method right' do
+ @allocation1.should_receive(:process!).once.with(4,0).and_return [1, 2, 3, 4]
+ @allocation2.should_receive(:process!).never
+ @allocation3.should_receive(:process!).never
+
+ @allocations.process! @amount, @offset, 0
+ end
+ end
+ context 'larger amount and early 1' do
+ before(:each) do
+ @amount = 4
+ @offset = 0
+ end
+ it 'should call the process! method right' do
+ @allocation1.should_receive(:process!).once.with(4,0).and_return [1, 2, 3, 4]
+ @allocation2.should_receive(:process!).once.with(0,0).and_return []
+ @allocation3.should_receive(:process!).never
+
+ @allocations.process! @amount, @offset, 1
+ end
+ end
+ context 'larger amount and early 0' do
+ before(:each) do
+ @amount = 5
+ @offset = 0
+ end
+ it 'should call the process! method right' do
+ @allocation1.should_receive(:process!).once.with(5,0).and_return [1, 2, 3, 4]
+ @allocation2.should_receive(:process!).once.with(1,0).and_return [5]
+ @allocation3.should_receive(:process!).never
+
+ @allocations.process! @amount, @offset, 0
+ end
+ end
+ context 'larger amount and early 1' do
+ before(:each) do
+ @amount = 5
+ @offset = 0
+ end
+ it 'should call the process! method right' do
+ @allocation1.should_receive(:process!).once.with(5,0).and_return [1, 2, 3, 4]
+ @allocation2.should_receive(:process!).once.with(1,0).and_return [5]
+ @allocation3.should_receive(:process!).never
+
+ @allocations.process! @amount, @offset, 1
+ end
+ end
+ context 'larger amount and early 1' do
+ before(:each) do
+ @amount = 8
+ @offset = 0
+ end
+ it 'should call the process! method right' do
+ @allocation1.should_receive(:process!).once.with(8,0).and_return [1, 2, 3, 4]
+ @allocation2.should_receive(:process!).once.with(4,0).and_return [5, 6, 7]
+ @allocation3.should_receive(:process!).once.with(1,0).and_return [8]
+
+ @allocations.process! @amount, @offset, 1
+ end
+ end
end
describe 'amount spanning 3 allocations' do
before(:each) do
@@ -162,7 +253,8 @@
end
it 'should return certain ids' do
@allocation1.should_receive(:process!).once.with(3,0).and_return [1,2,3]
- @allocation2.should_receive(:process!).once.with(0,0)
+ @allocation2.should_receive(:process!).once.with(0,0).and_return []
+ @allocation3.should_receive(:process!).once.with(0,0).and_return []
@allocations.process! @amount, @offset
end
@@ -174,6 +266,7 @@
it 'should return certain ids' do
@allocation1.should_receive(:process!).once.with(3,3).and_return [4]
@allocation2.should_receive(:process!).once.with(2,0).and_return [5,6]
+ @allocation3.should_receive(:process!).once.with(0,0).and_return []
@allocations.process! @amount, @offset
end
View
2  version.rb
@@ -1,3 +1,3 @@
module Picky
- VERSION = '3.6.13'
+ VERSION = '3.6.14'
end
Please sign in to comment.
Something went wrong with that request. Please try again.