diff --git a/MyTimeline.py b/MyTimeline.py index 8b72e9a..f980871 100644 --- a/MyTimeline.py +++ b/MyTimeline.py @@ -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: