mirror of https://github.com/jumpserver/jumpserver
fix: 修复缓存框架组织切换问题&组织的 resource_statistics 字段是只读
parent
083f061665
commit
e61511372c
|
@ -84,7 +84,7 @@ class Cache(metaclass=CacheBase):
|
||||||
logger.info(f'CACHE: set {self.key} = {to_json}, timeout={self.timeout}')
|
logger.info(f'CACHE: set {self.key} = {to_json}, timeout={self.timeout}')
|
||||||
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 = []
|
field_descs = []
|
||||||
if not fields:
|
if not fields:
|
||||||
field_descs = self.field_desc_mapper.values()
|
field_descs = self.field_desc_mapper.values()
|
||||||
|
@ -109,7 +109,7 @@ class Cache(metaclass=CacheBase):
|
||||||
uncomputed_keys = all_keys - computed_keys
|
uncomputed_keys = all_keys - computed_keys
|
||||||
else:
|
else:
|
||||||
computed_data = {}
|
computed_data = {}
|
||||||
data = self._compute_data(*uncomputed_keys)
|
data = self.compute_data(*uncomputed_keys)
|
||||||
data.update(computed_data)
|
data.update(computed_data)
|
||||||
self.set_data(data)
|
self.set_data(data)
|
||||||
return data
|
return data
|
||||||
|
@ -134,7 +134,7 @@ class Cache(metaclass=CacheBase):
|
||||||
self.compute_and_set_all_data()
|
self.compute_and_set_all_data()
|
||||||
return
|
return
|
||||||
|
|
||||||
refresh_data = self._compute_data(*fields)
|
refresh_data = self.compute_data(*fields)
|
||||||
if not self.refresh_part_data_with_lock(refresh_data):
|
if not self.refresh_part_data_with_lock(refresh_data):
|
||||||
# 刷新部分失败,缓存中没有数据,更新所有的值
|
# 刷新部分失败,缓存中没有数据,更新所有的值
|
||||||
self.compute_and_set_all_data(refresh_data)
|
self.compute_and_set_all_data(refresh_data)
|
||||||
|
|
|
@ -20,9 +20,9 @@ class OrgRelatedCache(Cache):
|
||||||
"""
|
"""
|
||||||
return self.current_org
|
return self.current_org
|
||||||
|
|
||||||
def refresh(self, *fields):
|
def compute_data(self, *fields):
|
||||||
with tmp_to_org(self.get_current_org()):
|
with tmp_to_org(self.get_current_org()):
|
||||||
return super().refresh(*fields)
|
return super().compute_data(*fields)
|
||||||
|
|
||||||
def refresh_async(self, *fields):
|
def refresh_async(self, *fields):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -31,7 +31,7 @@ class OrgSerializer(ModelSerializer):
|
||||||
admins = serializers.PrimaryKeyRelatedField(many=True, queryset=User.objects.all(), write_only=True, required=False)
|
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)
|
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:
|
class Meta:
|
||||||
model = Organization
|
model = Organization
|
||||||
|
|
Loading…
Reference in New Issue