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:
parent
a8dc9322bf
commit
4f757aeeb4
@ -473,7 +473,7 @@ class MyTimelineView(NavigationView):
|
|||||||
self._cached_min_date: Optional[int] = None
|
self._cached_min_date: Optional[int] = None
|
||||||
self._cached_max_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_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
|
self._normalized_active_event_types: Optional[Set[int]] = None # Pre-computed normalized active types
|
||||||
|
|
||||||
# Filter state
|
# Filter state
|
||||||
@ -2064,10 +2064,7 @@ class MyTimelineView(NavigationView):
|
|||||||
Returns:
|
Returns:
|
||||||
int: The integer value of the event type.
|
int: The integer value of the event type.
|
||||||
"""
|
"""
|
||||||
# Check cache first
|
# Normalize to integer first (fast operation)
|
||||||
if event_type in self._event_type_normalization_cache:
|
|
||||||
return self._event_type_normalization_cache[event_type]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if isinstance(event_type, int):
|
if isinstance(event_type, int):
|
||||||
normalized = event_type
|
normalized = event_type
|
||||||
@ -2078,8 +2075,12 @@ class MyTimelineView(NavigationView):
|
|||||||
except (TypeError, ValueError, AttributeError):
|
except (TypeError, ValueError, AttributeError):
|
||||||
normalized = 0 # Default to 0 if conversion fails
|
normalized = 0 # Default to 0 if conversion fails
|
||||||
|
|
||||||
# Cache the result
|
# Use normalized value as cache key (ensures same values share same key)
|
||||||
self._event_type_normalization_cache[event_type] = normalized
|
# 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
|
return normalized
|
||||||
|
|
||||||
def _is_event_type_enabled(self, event_type: EventType) -> bool:
|
def _is_event_type_enabled(self, event_type: EventType) -> bool:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user