made the pager return keys in order
This commit is contained in:
parent
fbccbd73e0
commit
15884184aa
1 changed files with 20 additions and 6 deletions
26
lib/pager.rb
26
lib/pager.rb
|
@ -75,13 +75,27 @@ class CouchRest
|
|||
startkey = endkey
|
||||
end
|
||||
|
||||
grouped = rows.group_by{|r|r['key']}
|
||||
grouped.each do |k, rs|
|
||||
vs = rs.collect{|r|r['value']}
|
||||
yield(k,vs)
|
||||
end
|
||||
# grouped = rows.group_by{|r|r['key']}
|
||||
# grouped.each do |k, rs|
|
||||
# vs = rs.collect{|r|r['value']}
|
||||
# yield(k,vs)
|
||||
# end
|
||||
|
||||
# lastprocessedkey = rows.last['key']
|
||||
key = :begin
|
||||
values = []
|
||||
|
||||
rows.each do |r|
|
||||
if key != r['key']
|
||||
# we're on a new key, yield the old first and then reset
|
||||
yield(key, values) if key != :begin
|
||||
key = r['key']
|
||||
values = []
|
||||
end
|
||||
# keep accumulating
|
||||
values << r['value']
|
||||
end
|
||||
yield(key, values)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue