-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimize DocSettings:open() calls #11437
Conversation
if not provider then -- check associated | ||
local provider_key = DocumentRegistry:getAssociatedProviderKey(file) | ||
provider = provider_key and DocumentRegistry:getProviderFromKey(provider_key) | ||
if provider == nil then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for clarity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean nil
, I think it's just a matter of taste, now I tend to use not
for boolean values only. Not strong opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit heavy to review, so trusting you.
Two ideas: |
self.bookinfo = file_manager.coverbrowser and file_manager.coverbrowser:getBookInfo(file) | ||
table.insert(buttons, filemanagerutil.genStatusButtonsRow(file, close_dialog_refresh_callback)) | ||
local doc_settings_or_file | ||
if has_sidecar then | ||
doc_settings_or_file = DocSettings:open(file) | ||
if not self.bookinfo then | ||
local props = doc_settings_or_file:readSetting("doc_props") | ||
self.bookinfo = FileManagerBookInfo.extendProps(props, file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it a bit odd to store in self
(FileManager) some bookinfo (about a specific book), but looks like it comes from another recent PR #11404. So, nothing new.
But just asking: the bookinfo of the "last file long-pressed" (right?) is held in here as self.bookinfo until another one is long-pressed ? Or is it cleaned up at some point? No problem keeping a reference to it for a long time even if no longer of interest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, not in FM but in the file_chooser
instance.
It is not cleaned if no other file is long-pressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At a very quick glance at that module, it can contain a self.document
reference, so that is very very much an issue if this one is still live!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one?
self.bookinfo
contains book props from the sql db.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at FileManagerBookInfo
itself, which I assumed is what self.bookinfo
points to. If it only contains props, I would suggest renaming that variable instead ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an existing convention with FM/RD modules where self.thing
points to the active instance of the AppThing
module, which explains my confusion ;).
(e.g., ReaderZooming
-> self.zooming)
And...
koreader/frontend/apps/reader/readerui.lua
Lines 418 to 423 in 962477e
-- book info | |
self:registerModule("bookinfo", FileManagerBookInfo:new{ | |
dialog = self.dialog, | |
document = self.document, | |
ui = self, | |
}) |
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, you mean
self:registerModule("bookinfo", FileManagerBookInfo:new{ ui = self }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, exactly ;).
So, yeah, if that's not really that, I'd feel less confused with a better variable name then ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, self.cachedbookinfo
, to avoid names doubling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it only contaiins book properties, having a prop
in there sounds sensible to me, but it's your show ;).
-- try to stay on current page | ||
local select_number = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer try ? :) Why not? Or is it magically ensured somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We pass -1 in switchItemTable
and stay on the page even after removing an item.
Have I missed anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I just didn't know (or forgot) about the effect of -1
:
koreader/frontend/ui/widget/menu.lua
Lines 1143 to 1157 in 962477e
--[[ | |
the itemnumber paramter determines menu page number after switching item table | |
1. itemnumber >= 0 | |
the page number is calculated with items per page | |
2. itemnumber == nil | |
the page number is 1 | |
3. itemnumber is negative number | |
the page number is not changed, used when item_table is appended with | |
new entries | |
alternatively, itemmatch may be provided as a {key = value} table, | |
and the page number will be the page containing the first item for | |
which item.key = value | |
--]] | |
function Menu:switchItemTable(new_title, new_item_table, itemnumber, itemmatch, new_subtitle) |
So, if it works as stated, no problem :)
Thanks for the details (worth adding to the first post when you open a PR so the discovery is made easier :). |
Still hesitating with the name.
or koreader/frontend/apps/filemanager/filemanager.lua Lines 281 to 282 in 1fe9084
|
Random hijack to mention some issue, not sure it's related to this PR, but maybe, or to some similar one.
|
Recently added features (status buttons in file popup dialogs, aux providers support, frozen history for finished books) caused extra
DocSettings:open()
calls. Opening a book from the file browser gives 4 calls, popup file dialog gives 3 calls.With this PR the number of calls is reduced: 2 calls while opening a book (that is the required minimum), 1 call for the popup dialog in FM, Hist, Coll.
This change is