def get_doc_count(model_class, where, entity, domain):
    from corehq.apps.domain.dbaccessors import get_doc_count_in_domain_by_type
    from ...missingdocs import MissingIds
    sql_estimate = estimate_partitioned_row_count(model_class, where)
    couchdb = XFormInstance.get_db()
    couch_count = sum(
        get_doc_count_in_domain_by_type(domain, doc_type, couchdb)
        for doc_type in MissingIds.DOC_TYPES[entity])
    return min(sql_estimate, couch_count)
def iter_chunks(model_class, field, domain, chunk_size=5000):
    where = Q(domain=domain)
    row_count = estimate_partitioned_row_count(model_class, where)
    rows = paginate_query_across_partitioned_databases(
        model_class,
        where,
        values=[field],
        load_source='couch_to_sql_migration',
        query_size=chunk_size,
    )
    values = (r[0] for r in rows)
    values = with_progress_bar(values, row_count, oneline="concise")
    yield from chunked(values, chunk_size, list)
Ejemplo n.º 3
0
def iter_ids(model_class, field, domain, chunk_size=1000):
    where = Q(domain=domain)
    rows = paginate_query_across_partitioned_databases(
        model_class,
        where,
        values=[field],
        load_source='delete_domain',
        query_size=chunk_size,
    )
    yield from with_progress_bar(
        (r[0] for r in rows),
        estimate_partitioned_row_count(model_class, where),
        prefix="",
        oneline="concise",
        stream=silence_during_tests(),
    )
def get_doc_count(model_class, where, entity, domain):
    sql_estimate = estimate_partitioned_row_count(model_class, where)
    couchdb = XFormInstance.get_db()
    couch_count = get_couch_doc_count(domain, entity, couchdb)
    return min(sql_estimate, couch_count)