Fix: Use hashable cache key for event type normalization

- Change cache key from EventType (unhashable) to normalized int
- Fixes TypeError: unhashable type: 'EventType' error
- Cache now uses normalized integer as both key and value

This ensures the cache works correctly with non-hashable EventType objects
while maintaining caching benefits for repeated conversions.
This commit is contained in:
Daniel Viegas 2025-11-30 01:33:32 +01:00
parent a8dc9322bf
commit 4f757aeeb4

View File

@ -473,7 +473,7 @@ class MyTimelineView(NavigationView):
self._cached_min_date: Optional[int] = None
self._cached_max_date: Optional[int] = None
self._event_to_person_cache: Dict[str, Optional['Person']] = {} # Event handle -> Person object (or None)
self._event_type_normalization_cache: Dict[EventType, int] = {} # Cache for event type normalization
self._event_type_normalization_cache: Dict[int, int] = {} # Cache for event type normalization (key: hash/id, value: normalized int)
self._normalized_active_event_types: Optional[Set[int]] = None # Pre-computed normalized active types
# Filter state
@ -2064,10 +2064,7 @@ class MyTimelineView(NavigationView):
Returns:
int: The integer value of the event type.
"""
# Check cache first
if event_type in self._event_type_normalization_cache:
return self._event_type_normalization_cache[event_type]
# Normalize to integer first (fast operation)
try:
if isinstance(event_type, int):
normalized = event_type
@ -2078,8 +2075,12 @@ class MyTimelineView(NavigationView):
except (TypeError, ValueError, AttributeError):
normalized = 0 # Default to 0 if conversion fails
# Cache the result
self._event_type_normalization_cache[event_type] = normalized
# Use normalized value as cache key (ensures same values share same key)
# Check cache - if we've seen this normalized value before, we already know it
# This cache is mainly useful for avoiding repeated int() calls on same objects
if normalized not in self._event_type_normalization_cache:
self._event_type_normalization_cache[normalized] = normalized
return normalized
def _is_event_type_enabled(self, event_type: EventType) -> bool: