Skip to content

Commit 5c2aee1

Browse files
committed
fix(permission_system): streamline cache handling for command permissions
- Simplified the cache retrieval logic by directly unwrapping values and removing unnecessary checks for malformed entries. - Improved logging to provide clearer messages for cache hits, enhancing traceability during cache operations. - Ensured that uncached commands are accurately tracked, improving overall cache management efficiency.
1 parent b97cbd2 commit 5c2aee1

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/tux/core/permission_system.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,10 @@ async def get_command_permission(
525525
raw = await self._cache_backend.get(backend_key)
526526
if raw is not None:
527527
unwrapped = unwrap_optional_perm(raw)
528-
if unwrapped is not None:
529-
logger.trace(
530-
f"Cache hit for command permission with fallback {command_name} (guild {guild_id})",
531-
)
532-
return unwrapped
533528
logger.trace(
534-
f"Malformed cache entry for command permission {command_name} (guild {guild_id}), resolving as miss",
529+
f"Cache hit for command permission with fallback {command_name} (guild {guild_id})",
535530
)
531+
return unwrapped
536532

537533
# For single-word commands (no parents), use direct query for efficiency
538534
parts = command_name.split()
@@ -636,14 +632,7 @@ async def batch_get_command_permissions(
636632
raw_values = await asyncio.gather(*get_coros)
637633
for (_, command_name), raw in zip(keys_and_names, raw_values, strict=True):
638634
if raw is not None:
639-
unwrapped = unwrap_optional_perm(raw)
640-
if unwrapped is not None:
641-
cached_results[command_name] = unwrapped
642-
else:
643-
logger.trace(
644-
f"Malformed cache entry for command permission {command_name} (guild {guild_id}), resolving as miss",
645-
)
646-
uncached_commands.append(command_name)
635+
cached_results[command_name] = unwrap_optional_perm(raw)
647636
else:
648637
uncached_commands.append(command_name)
649638

0 commit comments

Comments
 (0)