CoverBrowser: doc_settings cache improvement (#11360)

reviewable/pr11380/r1
hius07 4 months ago committed by GitHub
parent e3b4cbe71a
commit 43831236ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -130,24 +130,24 @@ end
-- Generate all book status file dialog buttons in a row -- Generate all book status file dialog buttons in a row
function filemanagerutil.genStatusButtonsRow(doc_settings_or_file, caller_callback) function filemanagerutil.genStatusButtonsRow(doc_settings_or_file, caller_callback)
local summary, status local file, summary, status
if type(doc_settings_or_file) == "table" then -- currently opened file if type(doc_settings_or_file) == "table" then -- currently opened file
file = doc_settings_or_file:readSetting("doc_path")
summary = doc_settings_or_file:readSetting("summary") summary = doc_settings_or_file:readSetting("summary")
status = summary.status status = summary.status
else else
status = filemanagerutil.getStatus(doc_settings_or_file) file = doc_settings_or_file
summary = {}
status = filemanagerutil.getStatus(file)
end end
local function genStatusButton(to_status) local function genStatusButton(to_status)
return { return {
text = filemanagerutil.statusToString(to_status) .. (status == to_status and "" or ""), text = filemanagerutil.statusToString(to_status) .. (status == to_status and "" or ""),
id = to_status, -- used by covermenu
enabled = status ~= to_status, enabled = status ~= to_status,
callback = function() callback = function()
if summary then -- currently opened file summary.status = to_status
summary.status = to_status filemanagerutil.setStatus(file, to_status)
else UIManager:broadcastEvent(Event:new("DocSettingsItemsChanged", file, { summary = summary })) -- for CoverBrowser
filemanagerutil.setStatus(doc_settings_or_file, to_status)
end
caller_callback() caller_callback()
end, end,
} }
@ -169,7 +169,6 @@ function filemanagerutil.genResetSettingsButton(file, caller_callback, button_di
local has_custom_metadata_file = custom_metadata_file and true or false local has_custom_metadata_file = custom_metadata_file and true or false
return { return {
text = _("Reset"), text = _("Reset"),
id = "reset", -- used by covermenu
enabled = not button_disabled and (has_sidecar_file or has_custom_metadata_file or has_custom_cover_file), enabled = not button_disabled and (has_sidecar_file or has_custom_metadata_file or has_custom_cover_file),
callback = function() callback = function()
local CheckButton = require("ui/widget/checkbutton") local CheckButton = require("ui/widget/checkbutton")
@ -191,6 +190,7 @@ function filemanagerutil.genResetSettingsButton(file, caller_callback, button_di
UIManager:broadcastEvent(Event:new("InvalidateMetadataCache", file)) UIManager:broadcastEvent(Event:new("InvalidateMetadataCache", file))
end end
if data_to_purge.doc_settings then if data_to_purge.doc_settings then
UIManager:broadcastEvent(Event:new("DocSettingsItemsChanged", file)) -- for CoverBrowser
require("readhistory"):fileSettingsPurged(file) require("readhistory"):fileSettingsPurged(file)
end end
caller_callback() caller_callback()

@ -40,8 +40,6 @@ local nb_drawings_since_last_collectgarbage = 0
-- in the real Menu class or instance -- in the real Menu class or instance
local CoverMenu = {} local CoverMenu = {}
local book_statuses = {"reading", "abandoned", "complete"}
function CoverMenu:updateCache(file, status, do_create, pages) function CoverMenu:updateCache(file, status, do_create, pages)
if do_create then -- create new cache entry if absent if do_create then -- create new cache entry if absent
if self.cover_info_cache[file] then return end if self.cover_info_cache[file] then return end
@ -314,33 +312,8 @@ function CoverMenu:updateItems(select_number)
buttons = orig_buttons, buttons = orig_buttons,
} }
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.file_dialog:getButtonById("reset")
if button then
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
end
-- Fudge the status change button callbacks to also update the cover_info_cache
for _, status in ipairs(book_statuses) do
button = self.file_dialog:getButtonById(status)
if not button then break end -- status buttons are not shown
local orig_status_callback = button.callback
button.callback = function()
-- Update the cache
self:updateCache(file, status)
-- And then set the status on file as expected
orig_status_callback()
end
end
-- Replace the "Book information" button callback to use directly our bookinfo -- Replace the "Book information" button callback to use directly our bookinfo
button = self.file_dialog:getButtonById("book_information") local button = self.file_dialog:getButtonById("book_information")
button.callback = function() button.callback = function()
FileManagerBookInfo:show(file, FileManagerBookInfo.extendProps(bookinfo)) FileManagerBookInfo:show(file, FileManagerBookInfo.extendProps(bookinfo))
UIManager:close(self.file_dialog) UIManager:close(self.file_dialog)
@ -445,33 +418,8 @@ function CoverMenu:onHistoryMenuHold(item)
buttons = orig_buttons, buttons = orig_buttons,
} }
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.histfile_dialog:getButtonById("reset")
if button then
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
end
-- Fudge the status change button callbacks to also update the cover_info_cache
for _, status in ipairs(book_statuses) do
button = self.histfile_dialog:getButtonById(status)
if not button then break end -- status buttons are not shown
local orig_status_callback = button.callback
button.callback = function()
-- Update the cache
self:updateCache(file, status)
-- And then set the status on file as expected
orig_status_callback()
end
end
-- Replace the "Book information" button callback to use directly our bookinfo -- Replace the "Book information" button callback to use directly our bookinfo
button = self.histfile_dialog:getButtonById("book_information") local button = self.histfile_dialog:getButtonById("book_information")
button.callback = function() button.callback = function()
FileManagerBookInfo:show(file, FileManagerBookInfo.extendProps(bookinfo)) FileManagerBookInfo:show(file, FileManagerBookInfo.extendProps(bookinfo))
UIManager:close(self.histfile_dialog) UIManager:close(self.histfile_dialog)
@ -569,33 +517,8 @@ function CoverMenu:onCollectionsMenuHold(item)
buttons = orig_buttons, buttons = orig_buttons,
} }
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.collfile_dialog:getButtonById("reset")
if button then
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
end
-- Fudge the status change button callbacks to also update the cover_info_cache
for _, status in ipairs(book_statuses) do
button = self.collfile_dialog:getButtonById(status)
if not button then break end -- status buttons are not shown
local orig_status_callback = button.callback
button.callback = function()
-- Update the cache
self:updateCache(file, status)
-- And then set the status on file as expected
orig_status_callback()
end
end
-- Replace the "Book information" button callback to use directly our bookinfo -- Replace the "Book information" button callback to use directly our bookinfo
button = self.collfile_dialog:getButtonById("book_information") local button = self.collfile_dialog:getButtonById("book_information")
button.callback = function() button.callback = function()
FileManagerBookInfo:show(file, FileManagerBookInfo.extendProps(bookinfo)) FileManagerBookInfo:show(file, FileManagerBookInfo.extendProps(bookinfo))
UIManager:close(self.collfile_dialog) UIManager:close(self.collfile_dialog)

@ -519,9 +519,8 @@ function CoverBrowser.initGrid(menu, display_mode)
end end
function CoverBrowser:refreshFileManagerInstance(cleanup, post_init) function CoverBrowser:refreshFileManagerInstance(cleanup, post_init)
local fm = FileManager.instance local fc = self.ui.file_chooser
if fm then if fc then
local fc = fm.file_chooser
if cleanup then -- clean instance properties we may have set if cleanup then -- clean instance properties we may have set
if fc.showFileDialog_orig then if fc.showFileDialog_orig then
-- remove our showFileDialog that extended file_dialog with new buttons -- remove our showFileDialog that extended file_dialog with new buttons
@ -574,6 +573,7 @@ function CoverBrowser:setupFileManagerDisplayMode(display_mode)
FileChooser._recalculateDimen = _FileChooser__recalculateDimen_orig FileChooser._recalculateDimen = _FileChooser__recalculateDimen_orig
FileManager.tapPlus = _FileManager_tapPlus_orig FileManager.tapPlus = _FileManager_tapPlus_orig
-- Also clean-up what we added, even if it does not bother original code -- Also clean-up what we added, even if it does not bother original code
FileChooser.updateCache = nil
FileChooser._updateItemsBuildUI = nil FileChooser._updateItemsBuildUI = nil
FileChooser._do_cover_images = nil FileChooser._do_cover_images = nil
FileChooser._do_filename_only = nil FileChooser._do_filename_only = nil
@ -796,6 +796,23 @@ function CoverBrowser:onInvalidateMetadataCache(file)
return true return true
end end
function CoverBrowser:onDocSettingsItemsChanged(file, doc_settings)
local status -- nil to wipe the covermenu book cache
if doc_settings then
status = doc_settings.summary and doc_settings.summary.status
if not status then return end -- changes not for us
end
if self.ui.file_chooser then
self.ui.file_chooser:updateCache(file, status)
end
if self.ui.history and self.ui.history.hist_menu then
self.ui.history.hist_menu:updateCache(file, status)
end
if self.ui.collections and self.ui.collections.coll_menu then
self.ui.collections.coll_menu:updateCache(file, status)
end
end
function CoverBrowser:extractBooksInDirectory(path) function CoverBrowser:extractBooksInDirectory(path)
local Trapper = require("ui/trapper") local Trapper = require("ui/trapper")
Trapper:wrap(function() Trapper:wrap(function()

Loading…
Cancel
Save