Ejemplo n.º 1
0
def _get_unprocessed_form_iterator(domain):
    return CouchDomainDocTypeChangeProvider(
        couch_db=XFormInstance.get_db(),
        domains=[domain],
        doc_types=UNPROCESSED_DOC_TYPES,
        event_handler=PaginationEventHandler(),
    )
Ejemplo n.º 2
0
def _get_main_form_iterator(domain):
    return CouchDomainDocTypeChangeProvider(
        couch_db=XFormInstance.get_db(),
        domains=[domain],
        doc_types=['XFormInstance'],
        event_handler=PaginationEventHandler(),
    )
Ejemplo n.º 3
0
def _get_case_iterator(domain, doc_types=None):
    doc_types = doc_types or CASE_DOC_TYPES
    return CouchDomainDocTypeChangeProvider(
        couch_db=XFormInstance.get_db(),
        domains=[domain],
        doc_types=doc_types,
        event_handler=PaginationEventHandler(),
    )
Ejemplo n.º 4
0
def paginate_view(db,
                  view_name,
                  chunk_size,
                  event_handler=PaginationEventHandler(),
                  **view_kwargs):
    """
    intended as a more performant drop-in replacement for

        iter(db.view(view_name, **kwargs))

    intended specifically to be more performant when dealing with
    large numbers of rows

    Note: If the contents of the couch view do not change over the duration of
    the paginate_view call, this is guaranteed to have the same results
    as a direct view call. If the view is updated, however,
    paginate_views may skip docs that were added/updated during this period
    or may include docs that were removed/updated during this period.
    For this reason, it's best to use this with views that update infrequently
    or that are sorted by date modified and/or add-only,
    or when exactness is not a strict requirement

    chunk_size is how many docs to fetch per request to couchdb

    """
    if view_kwargs.get('reduce', True):
        raise ValueError('paginate_view must be called with reduce=False')

    if 'limit' in view_kwargs:
        raise ValueError('paginate_view cannot be called with limit')

    if 'skip' in view_kwargs:
        raise ValueError('paginate_view cannot be called with skip')

    view_kwargs['limit'] = chunk_size

    def call_view(**view_kwargs):
        return db.view(view_name, **view_kwargs)

    args_provider = PaginatedViewArgsProvider(view_kwargs)

    for result in paginate_function(call_view, args_provider, event_handler):
        yield result