2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
22 from mygpo
.couch
import get_main_database
26 def multi_request_view(cls
, view
, wrap
=True, auto_advance
=True,
29 splits up a view request into several requests, which reduces
30 the server load of the number of returned objects is large.
32 NOTE: As such a split request is obviously not atomical anymore, results
33 might skip some elements of contain some twice
35 If auto_advance is False the method will always request the same range.
36 This can be useful when the view contain unprocessed items and the caller
37 processes the items, thus removing them from the view before the next
41 per_page
= kwargs
.get('limit', 1000)
42 kwargs
['limit'] = per_page
+ 1
43 db
= get_main_database()
44 wrapper
= kwargs
.pop('wrapper', cls
.wrap
)
49 resp
= db
.view(view
, *args
, **kwargs
)
52 for n
, obj
in enumerate(resp
.iterator()):
57 doc
= wrapper(obj
['doc']) if wrapper
else obj
['doc']
58 docid
= doc
._id
if wrapper
else obj
['id']
60 docid
= obj
.get('id', None)
65 kwargs
['startkey'] = key
67 kwargs
['startkey_docid'] = docid
71 # we reached the end of the page, load next one
79 def is_couchdb_id(id_str
):
80 f
= functools
.partial(operator
.contains
, string
.hexdigits
)
81 return len(id_str
) == 32 and all(map(f
, id_str
))