<s> from casexml . apps . case . models import CommCareCase <EOL> from corehq . form_processor . backends . sql . dbaccessors import CaseAccessorSQL <EOL> from corehq . form_processor . change_providers import _sql_case_to_change <EOL> from corehq . form_processor . utils . general import should_use_sql_backend <EOL> from pillowtop . reindexer . change_providers . composite import CompositeChangeProvider <EOL> from pillowtop . reindexer . change_providers . couch import CouchViewChangeProvider <EOL> from pillowtop . reindexer . change_providers . interface import ChangeProvider <EOL> def get_couch_domain_case_change_provider ( domain ) : <EOL> return CouchViewChangeProvider ( <EOL> couch_db = CommCareCase . get_db ( ) , <EOL> view_name = '<STR_LIT>' , <EOL> chunk_size = <NUM_LIT:100> , <EOL> view_kwargs = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ domain ] , <EOL> '<STR_LIT>' : [ domain , { } , { } ] <EOL> } <EOL> ) <EOL> class SqlDomainCaseChangeProvider ( ChangeProvider ) : <EOL> def __init__ ( self , domain ) : <EOL> self . domain = domain <EOL> def iter_all_changes ( self , start_from = None ) : <EOL> case_ids = CaseAccessorSQL . get_case_ids_in_domain ( self . domain ) <EOL> for case in CaseAccessorSQL . get_cases ( case_ids ) : <EOL> yield _sql_case_to_change ( case ) <EOL> def get_domain_case_change_provider ( domains ) : <EOL> change_providers = [ ] <EOL> for domain in domains : <EOL> if should_use_sql_backend ( domain ) : <EOL> change_providers . append ( SqlDomainCaseChangeProvider ( domain ) ) <EOL> else : <EOL> change_providers . append ( get_couch_domain_case_change_provider ( domain ) ) <EOL> return CompositeChangeProvider ( change_providers ) </s>
