2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00

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.
This commit is contained in:
hrdl 2023-05-18 20:08:50 +00:00 committed by GitHub
parent 796574e5cd
commit 20101baef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)