Cache OCR-negative bubbles
check / local-gate (push) Failing after 42s

This commit is contained in:
JWeBot Contributors
2026-10-16 11:38:03 +08:00
parent 572159f571
commit 22edf6ff15
17 changed files with 79 additions and 27 deletions
+11 -5
View File
@@ -1126,7 +1126,7 @@ class OcrEngine:
)
self._message_cache: OrderedDict[
str,
tuple[str, str, float, float, float],
tuple[str, str, float, float, float] | None,
] = OrderedDict()
self._scan_count = 0
self.last_cache_hits = 0
@@ -1202,7 +1202,7 @@ class OcrEngine:
def _cache(self) -> OrderedDict[
str,
tuple[str, str, float, float, float],
tuple[str, str, float, float, float] | None,
]:
cache = getattr(self, "_message_cache", None)
if cache is None:
@@ -1282,15 +1282,17 @@ class OcrEngine:
bubble_crop = image.crop(
(bubble.x, bubble.y, bubble.right, bubble.bottom)
)
key = self._cache_key(sender_crop, bubble_crop)
sequence_signature = bubble_sequence_signature(
sender_crop,
bubble_crop,
)
cached = cache.get(key)
if cached is not None:
key = sequence_signature
if key in cache:
cached = cache[key]
hits += 1
cache.move_to_end(key)
if cached is None:
continue
messages.append(
IncomingMessage(
sender=cached[0],
@@ -1311,6 +1313,10 @@ class OcrEngine:
visual_signature=sequence_signature,
)
if message is None:
cache[key] = None
cache.move_to_end(key)
while len(cache) > OCR_MESSAGE_CACHE_SIZE:
cache.popitem(last=False)
continue
cache[key] = (
message.sender,