def __init__(self, project, restore_user, params, is_async=False, overwrite_cache=False, case_sync=None): if not project or not project.name: raise Exception('you are not allowed to make a RestoreState without a domain!') self.project = project self.domain = project.name self.restore_user = restore_user self.params = params self.provider_log = {} # individual data providers can log stuff here # get set in the start_sync() function self.start_time = None self.duration = None self.current_sync_log = None self.is_async = is_async self.overwrite_cache = overwrite_cache self._last_sync_log = Ellipsis if case_sync is None: if LIVEQUERY_SYNC.enabled(self.domain): case_sync = LIVEQUERY else: case_sync = DEFAULT_CASE_SYNC if case_sync not in [LIVEQUERY, CLEAN_OWNERS]: raise ValueError("unknown case sync algorithm: %s" % case_sync) self._case_sync = case_sync self.is_livequery = case_sync == LIVEQUERY
def _get_all_dirtiness_flags_from_cases(domain, case_db, touched_cases): # process the temporary dirtiness flags first so that any hints for real dirtiness get overridden if LIVEQUERY_SYNC.enabled(domain): return [] dirtiness_flags = list( _get_dirtiness_flags_for_reassigned_case(list(touched_cases.values()))) for case_update_meta in touched_cases.values(): dirtiness_flags += list( _get_dirtiness_flags_for_outgoing_indices(case_db, case_update_meta.case)) dirtiness_flags += list( _get_dirtiness_flags_for_child_cases( case_db, [meta.case for meta in touched_cases.values()])) return dirtiness_flags
def commit_dirtiness_flags(self): """ Updates any dirtiness flags in the database. """ if self.domain and not LIVEQUERY_SYNC.enabled(self.domain): flags_to_save = self.get_flags_to_save() if should_create_flags_on_submission(self.domain): assert settings.UNIT_TESTING # this is currently only true when unit testing all_touched_ids = set( flags_to_save.keys()) | self.get_clean_owner_ids() to_update = { f.owner_id: f for f in OwnershipCleanlinessFlag.objects.filter( domain=self.domain, owner_id__in=list(all_touched_ids), ) } for owner_id in all_touched_ids: if owner_id not in to_update: # making from scratch - default to clean, but set to dirty if needed flag = OwnershipCleanlinessFlag(domain=self.domain, owner_id=owner_id, is_clean=True) if owner_id in flags_to_save: flag.is_clean = False flag.hint = flags_to_save[owner_id] flag.save() else: # updating - only save if we are marking dirty or setting a hint flag = to_update[owner_id] if owner_id in flags_to_save and (flag.is_clean or not flag.hint): flag.is_clean = False flag.hint = flags_to_save[owner_id] flag.save() else: # only update the flags that are already in the database flags_to_update = OwnershipCleanlinessFlag.objects.filter( Q(domain=self.domain), Q(owner_id__in=list(flags_to_save)), Q(is_clean=True) | Q(hint__isnull=True)) for flag in flags_to_update: flag.is_clean = False flag.hint = flags_to_save[flag.owner_id] flag.save()