AutoSave: Delay I/O until after the pageturn (#6917)

nextTick was too early ;).

Prevents small hitches when turning the page for the page where this
triggers.

Apply the same trickery to the Stats DB insert, even if that one probably
had a much smaller impact.
pull/6927/head
NiLuJe 3 years ago committed by GitHub
parent 931f01ef26
commit bba8b31e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -967,10 +967,12 @@ function ReaderView:checkAutoSaveSettings()
if not interval then -- no auto save
return
end
local now_ts = os.time()
if now_ts - self.settings_last_save_ts >= interval*60 then
self.settings_last_save_ts = now_ts
UIManager:nextTick(function()
-- I/O, delay until after the pageturn
UIManager:tickAfterNext(function()
self.ui:saveSettings()
end)
end

@ -2173,8 +2173,12 @@ function ReaderStatistics:onPageUpdate(pageno)
-- We want a flush to db every 50 page turns
if self.pageturn_count >= MAX_PAGETURNS_BEFORE_FLUSH then
self:insertDB(self.id_curr_book)
-- insertDB will call resetVolatileStats for us ;)
-- I/O, delay until after the pageturn, but reset the count now, to avoid potentially scheduling multiple inserts...
self.pageturn_count = 0
UIManager:tickAfterNext(function()
self:insertDB(self.id_curr_book)
-- insertDB will call resetVolatileStats for us ;)
end)
end
-- Update average time per page (if need be, insertDB will have updated the totals and cleared the volatiles)

Loading…
Cancel
Save