mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Avoid recalculation of partial_md5_checksum at each opening (#3352)
This is done by/for kosync plugin at each opening, because the docsettings was re-opened and saved for this, but later overwritten by the current koreader docsettings - so it was redone each time. This correctly adds this partial_md5_checksum to the current koreader docsettings, which will be saved on document closing - so it will not be redone next time. Note: this partial_md5_checksum is not (yet) used by anything.
This commit is contained in:
@@ -120,13 +120,18 @@ end
|
||||
-- Note that if PDF file size is around 1024, 4096, 16384, 65536, 262144
|
||||
-- 1048576, 4194304, 16777216, 67108864, 268435456 or 1073741824, appending data
|
||||
-- by highlighting in KOReader may change the digest value.
|
||||
function Document:fastDigest()
|
||||
function Document:fastDigest(docsettings)
|
||||
if not self.file then return end
|
||||
local file = io.open(self.file, 'rb')
|
||||
if file then
|
||||
local docsettings = require("docsettings"):open(self.file)
|
||||
local tmp_docsettings = false
|
||||
if not docsettings then -- if not provided, open/create it
|
||||
docsettings = require("docsettings"):open(self.file)
|
||||
tmp_docsettings = true
|
||||
end
|
||||
local result = docsettings:readSetting("partial_md5_checksum")
|
||||
if not result then
|
||||
logger.dbg("computing and storing partial_md5_checksum")
|
||||
local md5 = require("ffi/MD5")
|
||||
local lshift = bit.lshift
|
||||
local step, size = 1024, 1024
|
||||
@@ -143,7 +148,9 @@ function Document:fastDigest()
|
||||
result = m:sum()
|
||||
docsettings:saveSetting("partial_md5_checksum", result)
|
||||
end
|
||||
docsettings:close()
|
||||
if tmp_docsettings then
|
||||
docsettings:close()
|
||||
end
|
||||
file:close()
|
||||
return result
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user