From e61511372c04a5bf1463ab120e0d22081244e6ab Mon Sep 17 00:00:00 2001 From: xinwen Date: Sun, 17 Jan 2021 19:10:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E7=BB=84=E7=BB=87=E5=88=87=E6=8D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98&=E7=BB=84=E7=BB=87=E7=9A=84=20resource=5Fstatistics?= =?UTF-8?q?=20=E5=AD=97=E6=AE=B5=E6=98=AF=E5=8F=AA=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/cache.py | 6 +++--- apps/orgs/cache.py | 4 ++-- apps/orgs/serializers.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) 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