don't send a getmore immediately after every query
This commit is contained in:
parent
2ef660986d
commit
dcda70fddd
@ -206,8 +206,9 @@ module XGen
|
||||
end
|
||||
|
||||
def refill_via_get_more
|
||||
send_query_if_needed
|
||||
return if @cursor_id == 0
|
||||
if send_query_if_needed or @cursor_id == 0
|
||||
return
|
||||
end
|
||||
@db._synchronize {
|
||||
@db.send_to_db(GetMoreMessage.new(@admin ? 'admin' : @db.name, @collection.name, @cursor_id))
|
||||
read_all
|
||||
@ -227,12 +228,15 @@ module XGen
|
||||
|
||||
def send_query_if_needed
|
||||
# Run query first time we request an object from the wire
|
||||
unless @query_run
|
||||
if @query_run
|
||||
false
|
||||
else
|
||||
@db._synchronize {
|
||||
@db.send_query_message(QueryMessage.new(@admin ? 'admin' : @db.name, @collection.name, @query))
|
||||
@query_run = true
|
||||
read_all
|
||||
}
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -145,4 +145,61 @@ class CursorTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_kill_cursors
|
||||
@@coll.drop
|
||||
|
||||
client_cursors = @@db.db_command("cursorInfo" => 1)["clientCursors_size"]
|
||||
by_location = @@db.db_command("cursorInfo" => 1)["byLocation_size"]
|
||||
|
||||
10000.times do |i|
|
||||
@@coll.insert("i" => i)
|
||||
end
|
||||
|
||||
assert_equal(client_cursors,
|
||||
@@db.db_command("cursorInfo" => 1)["clientCursors_size"])
|
||||
assert_equal(by_location,
|
||||
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
||||
|
||||
10.times do |i|
|
||||
@@coll.find_one()
|
||||
end
|
||||
|
||||
assert_equal(client_cursors,
|
||||
@@db.db_command("cursorInfo" => 1)["clientCursors_size"])
|
||||
assert_equal(by_location,
|
||||
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
||||
|
||||
10.times do |i|
|
||||
a = @@coll.find()
|
||||
a.next_object()
|
||||
a.close()
|
||||
end
|
||||
|
||||
assert_equal(client_cursors,
|
||||
@@db.db_command("cursorInfo" => 1)["clientCursors_size"])
|
||||
assert_equal(by_location,
|
||||
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
||||
|
||||
a = @@coll.find()
|
||||
a.next_object()
|
||||
|
||||
assert_not_equal(client_cursors,
|
||||
@@db.db_command("cursorInfo" => 1)["clientCursors_size"])
|
||||
assert_not_equal(by_location,
|
||||
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
||||
|
||||
a.close()
|
||||
|
||||
assert_equal(client_cursors,
|
||||
@@db.db_command("cursorInfo" => 1)["clientCursors_size"])
|
||||
assert_equal(by_location,
|
||||
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
||||
|
||||
a = @@coll.find({}, :limit => 10).next_object()
|
||||
|
||||
assert_equal(client_cursors,
|
||||
@@db.db_command("cursorInfo" => 1)["clientCursors_size"])
|
||||
assert_equal(by_location,
|
||||
@@db.db_command("cursorInfo" => 1)["byLocation_size"])
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user