Skip to content

Commit ed33acf

Browse files
committed
core/ports: Optimize attrdefs caching
1 parent 4db92bd commit ed33acf

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

qtoggleserver/core/ports.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,25 +306,27 @@ def initialize(self) -> None:
306306
pass
307307

308308
async def get_attrdefs(self) -> AttributeDefinitions:
309-
attrdefs_dicts = []
310-
311309
if self._standard_attrdefs_cache is None:
312310
self._standard_attrdefs_cache = dict(await self.get_standard_attrdefs())
313-
attrdefs_dicts.append(self._standard_attrdefs_cache)
311+
for name, attrdef in list(self._standard_attrdefs_cache.items()):
312+
enabled = attrdef.get('enabled', True)
313+
if callable(enabled):
314+
enabled = enabled(self)
315+
if inspect.isawaitable(enabled):
316+
enabled = await enabled
317+
if not enabled:
318+
self._standard_attrdefs_cache.pop(name)
319+
314320
if self._additional_attrdefs_cache is None:
315321
self._additional_attrdefs_cache = dict(await self.get_additional_attrdefs())
316-
attrdefs_dicts.append(self._additional_attrdefs_cache)
317-
318-
for attrdefs_dict in attrdefs_dicts:
319-
for name, attrdef in list(attrdefs_dict.items()):
322+
for name, attrdef in list(self._additional_attrdefs_cache.items()):
320323
enabled = attrdef.get('enabled', True)
321324
if callable(enabled):
322325
enabled = enabled(self)
323326
if inspect.isawaitable(enabled):
324327
enabled = await enabled
325-
326328
if not enabled:
327-
attrdefs_dict.pop(name)
329+
self._additional_attrdefs_cache.pop(name)
328330

329331
return self._standard_attrdefs_cache | self._additional_attrdefs_cache
330332

0 commit comments

Comments
 (0)