From 20101baef6ac759a32664a7209e5c97e93ba1e22 Mon Sep 17 00:00:00 2001 From: hrdl <31923882+hrdl-github@users.noreply.github.com> Date: Thu, 18 May 2023 20:08:50 +0000 Subject: [PATCH] pdfdocument: cache page text (#10450) Updating the selection queries the same page tens of times per second. This prevents KOReader from keeping up with high-frequency input event streams. Fixes #10443. Relies on koreader/koreader-base#1612. --- frontend/document/pdfdocument.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index b0bf0942e..63b7dfb35 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -103,10 +103,17 @@ function PdfDocument:comparePositions(pos1, pos2) end function PdfDocument:getPageTextBoxes(pageno) - local page = self._document:openPage(pageno) - local text = page:getPageText() - page:close() - return text + local hash = "textbox|"..self.file.."|"..pageno + local cached = DocCache:check(hash) + if not cached then + local page = self._document:openPage(pageno) + local text = page:getPageText() + page:close() + DocCache:insert(hash, CacheItem:new{text=text, size=text.size}) + return text + else + return cached.text + end end function PdfDocument:getPanelFromPage(pageno, pos)