change count to limit
This commit is contained in:
parent
ba8f84127c
commit
7aaffe5d63
6 changed files with 23 additions and 23 deletions
|
@ -5,13 +5,13 @@ module CouchRest
|
|||
@db = db
|
||||
end
|
||||
|
||||
def all_docs(count=100, &block)
|
||||
def all_docs(limit=100, &block)
|
||||
startkey = nil
|
||||
oldend = nil
|
||||
|
||||
while docrows = request_all_docs(count+1, startkey)
|
||||
while docrows = request_all_docs(limit+1, startkey)
|
||||
startkey = docrows.last['key']
|
||||
docrows.pop if docrows.length > count
|
||||
docrows.pop if docrows.length > limit
|
||||
if oldend == startkey
|
||||
break
|
||||
end
|
||||
|
@ -20,13 +20,13 @@ module CouchRest
|
|||
end
|
||||
end
|
||||
|
||||
def key_reduce(view, count=2000, firstkey = nil, lastkey = nil, &block)
|
||||
def key_reduce(view, limit=2000, firstkey = nil, lastkey = nil, &block)
|
||||
# start with no keys
|
||||
startkey = firstkey
|
||||
# lastprocessedkey = nil
|
||||
keepgoing = true
|
||||
|
||||
while keepgoing && viewrows = request_view(view, count, startkey)
|
||||
while keepgoing && viewrows = request_view(view, limit, startkey)
|
||||
startkey = viewrows.first['key']
|
||||
endkey = viewrows.last['key']
|
||||
|
||||
|
@ -37,7 +37,7 @@ module CouchRest
|
|||
# we need to do an offset thing to find the next startkey
|
||||
# otherwise we just get stuck
|
||||
lastdocid = viewrows.last['id']
|
||||
fornextloop = @db.view(view, :startkey => startkey, :startkey_docid => lastdocid, :count => 2)['rows']
|
||||
fornextloop = @db.view(view, :startkey => startkey, :startkey_docid => lastdocid, :limit => 2)['rows']
|
||||
|
||||
newendkey = fornextloop.last['key']
|
||||
if (newendkey == endkey)
|
||||
|
@ -79,18 +79,18 @@ module CouchRest
|
|||
|
||||
private
|
||||
|
||||
def request_all_docs count, startkey = nil
|
||||
def request_all_docs limit, startkey = nil
|
||||
opts = {}
|
||||
opts[:count] = count if count
|
||||
opts[:limit] = limit if limit
|
||||
opts[:startkey] = startkey if startkey
|
||||
results = @db.documents(opts)
|
||||
rows = results['rows']
|
||||
rows unless rows.length == 0
|
||||
end
|
||||
|
||||
def request_view view, count = nil, startkey = nil, endkey = nil
|
||||
def request_view view, limit = nil, startkey = nil, endkey = nil
|
||||
opts = {}
|
||||
opts[:count] = count if count
|
||||
opts[:limit] = limit if limit
|
||||
opts[:startkey] = startkey if startkey
|
||||
opts[:endkey] = endkey if endkey
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue