def _cached_case_id_to_case_name(case_id): key = 'case_id_to_case_name_cache_{id}'.format(id=case_id) ret = cache.get(key, NULL_CACHE_VALUE) if ret != NULL_CACHE_VALUE: return ret try: case = CommCareCase.get_lite(case_id) ret = case['name'] if "name" in case else None
def get(self, case_id): if not case_id: raise IllegalCaseId('case_id must not be empty') if case_id in self.cache: return self.cache[case_id] try: if self.strip_history: case_doc = CommCareCase.get_lite(case_id, wrap=self.wrap) elif self.lock: try: case_doc, lock = CommCareCase.get_locked_obj(_id=case_id) except redis.RedisError: case_doc = CommCareCase.get(case_id) else: self.locks.append(lock) else: if self.wrap: case_doc = CommCareCase.get(case_id) else: case_doc = CommCareCase.get_db().get(case_id) except ResourceNotFound: return None self.validate_doc(case_doc) self.cache[case_id] = case_doc return case_doc
def get_case_with_lock(case_id, lock=False, strip_history=False, wrap=False): def _get_case(): if wrap: return CommCareCase.get(case_id) else: return CommCareCase.get_db().get(case_id) try: if strip_history: case_doc = CommCareCase.get_lite(case_id, wrap=wrap) elif lock: try: case, lock = CommCareCase.get_locked_obj(_id=case_id) if case and not wrap: case = case.to_json() return case, lock except redis.RedisError: case_doc = _get_case() else: case_doc = _get_case() except ResourceNotFound: return None, None return case_doc, None
def _cached_case_id_to_case_name(case_id): key = 'case_id_to_case_name_cache_{id}'.format(id=case_id) ret = cache.get(key, NULL_CACHE_VALUE) if ret != NULL_CACHE_VALUE: return ret try: case = CommCareCase.get_lite(case_id) ret = case['name'] if "name" in case else None except ResourceNotFound: ret = None cache.set(key, ret) return ret
def get_case_with_lock(case_id, lock=False, strip_history=False, wrap=False): try: if strip_history: case_doc = CommCareCase.get_lite(case_id, wrap=wrap) elif lock: try: return CommCareCase.get_locked_obj(_id=case_id) except redis.RedisError: case_doc = CommCareCase.get(case_id) else: if wrap: case_doc = CommCareCase.get(case_id) else: case_doc = CommCareCase.get_db().get(case_id) except ResourceNotFound: return None, None return case_doc, None
def _get_case(self, case_id): try: if self.strip_history: case_doc = CommCareCase.get_lite(case_id, wrap=self.wrap) elif self.lock: try: case_doc, lock = CommCareCase.get_locked_obj(_id=case_id) except redis.RedisError: case_doc = CommCareCase.get(case_id) else: self.locks.append(lock) else: if self.wrap: case_doc = CommCareCase.get(case_id) else: case_doc = CommCareCase.get_db().get(case_id) except ResourceNotFound: return None return case_doc
def get_case_with_lock(case_id, lock=False, strip_history=False, wrap=False): def _get_case(): if wrap: return CommCareCase.get(case_id) else: return CommCareCase.get_db().get(case_id) try: if strip_history: case_doc = CommCareCase.get_lite(case_id, wrap=wrap) elif lock: try: case, lock = CommCareCase.get_locked_obj(_id=case_id) if case and not wrap: case = case.to_json() return case, lock except redis.RedisError: case_doc = _get_case()