def set_cached_payload_if_necessary(self, resp, duration):
        cache_payload = resp.get_cache_payload(bool(self.sync_log))
        if self.sync_log:
            # if there is a sync token, always cache
            try:
                data = cache_payload['data']
                self.sync_log.last_cached = datetime.utcnow()
                self.sync_log.hash_at_last_cached = str(self.sync_log.get_state_hash())
                self.sync_log.save()
                self.sync_log.set_cached_payload(data, self.version)
                try:
                    data.close()
                except AttributeError:
                    pass
            except ResourceConflict:
                # if one sync takes a long time and another one updates the sync log
                # this can fail. in this event, don't fail to respond, since it's just
                # a caching optimization
                pass
        else:
            # on initial sync, only cache if the duration was longer than the threshold
            if self.force_cache or timedelta(seconds=INITIAL_SYNC_CACHE_THRESHOLD) > duration:
                self.cache.set(self._initial_cache_key(), cache_payload, self.cache_timeout)
dataset/ETHPy150Open dimagi/commcare-hq/corehq/ex-submodules/casexml/apps/phone/restore.py/RestoreConfig.set_cached_payload_if_necessary/swapped operands of `>`