+11
-5
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user