diff --git a/apps/common/cache.py b/apps/common/cache.py index f7c0b16cd..8cf76154c 100644 --- a/apps/common/cache.py +++ b/apps/common/cache.py @@ -84,7 +84,7 @@ class Cache(metaclass=CacheBase): logger.info(f'CACHE: set {self.key} = {to_json}, timeout={self.timeout}') cache.set(self.key, to_json, timeout=self.timeout) - def _compute_data(self, *fields): + def compute_data(self, *fields): field_descs = [] if not fields: field_descs = self.field_desc_mapper.values() @@ -109,7 +109,7 @@ class Cache(metaclass=CacheBase): uncomputed_keys = all_keys - computed_keys else: computed_data = {} - data = self._compute_data(*uncomputed_keys) + data = self.compute_data(*uncomputed_keys) data.update(computed_data) self.set_data(data) return data @@ -134,7 +134,7 @@ class Cache(metaclass=CacheBase): self.compute_and_set_all_data() return - refresh_data = self._compute_data(*fields) + refresh_data = self.compute_data(*fields) if not self.refresh_part_data_with_lock(refresh_data): # 刷新部分失败,缓存中没有数据,更新所有的值 self.compute_and_set_all_data(refresh_data) diff --git a/apps/orgs/cache.py b/apps/orgs/cache.py index c77dd988f..9b1c8ffa9 100644 --- a/apps/orgs/cache.py +++ b/apps/orgs/cache.py @@ -20,9 +20,9 @@ class OrgRelatedCache(Cache): """ return self.current_org - def refresh(self, *fields): + def compute_data(self, *fields): with tmp_to_org(self.get_current_org()): - return super().refresh(*fields) + return super().compute_data(*fields) def refresh_async(self, *fields): """ diff --git a/apps/orgs/serializers.py b/apps/orgs/serializers.py index d10963531..e167aa525 100644 --- a/apps/orgs/serializers.py +++ b/apps/orgs/serializers.py @@ -31,7 +31,7 @@ class OrgSerializer(ModelSerializer): admins = serializers.PrimaryKeyRelatedField(many=True, queryset=User.objects.all(), write_only=True, required=False) auditors = serializers.PrimaryKeyRelatedField(many=True, queryset=User.objects.all(), write_only=True, required=False) - resource_statistics = ResourceStatisticsSerializer(source='resource_statistics_cache') + resource_statistics = ResourceStatisticsSerializer(source='resource_statistics_cache', read_only=True) class Meta: model = Organization