def paginate_view(db, view_name, chunk_size,
                  log_handler=PaginateViewLogHandler(), **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 view_kwargs in 'skip':
        raise ValueError('paginate_view cannot be called with skip')

    view_kwargs['limit'] = chunk_size
    total_emitted = 0
    len_results = -1
    while len_results:
        log_handler.view_starting(db, view_name, view_kwargs, total_emitted)
        start_time = datetime.datetime.utcnow()
        results = db.view(view_name, **view_kwargs)
        len_results = len(results)

        for result in results:
            yield result

        total_emitted += len_results
        log_handler.view_ending(db, view_name, view_kwargs, total_emitted,
                                datetime.datetime.utcnow() - start_time)
        if len_results:
            view_kwargs['startkey'] = result['key']
            view_kwargs['startkey_docid'] = result['id']
            view_kwargs['skip'] = 1
dataset/ETHPy150Open dimagi/commcare-hq/corehq/util/couch_helpers.py/paginate_view/swapped operands of `in`