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.
reviewable/pr10462/r1
hrdl 12 months ago committed by GitHub
parent 796574e5cd
commit 20101baef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save