Skip to content
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

Merged
merged 12 commits into from
Feb 7, 2024
Merged

Conversation

hius07
Copy link
Member

@hius07 hius07 commented Feb 4, 2024

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 Reviewable

if not provider then -- check associated
local provider_key = DocumentRegistry:getAssociatedProviderKey(file)
provider = provider_key and DocumentRegistry:getProviderFromKey(provider_key)
if provider == nil then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for clarity?

Copy link
Member Author

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.

@Frenzie Frenzie added this to the 2024.02 milestone Feb 4, 2024
Copy link
Contributor

@poire-z poire-z left a 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.

@hius07
Copy link
Member Author

hius07 commented Feb 5, 2024

A bit heavy to review

Two ideas:
(1) Opening a book: FileManager:openFile now gets the associated or registered provider and passes it to ReaderUI (previously FM checked for associated provider only, and then ReaderUI again got the provider to open the document).
(2) File popup dialogs in FM, Hist, Coll now get doc_settings at showup and pass it to the buttons that need it.

Comment on lines 276 to 282
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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

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!

Copy link
Member Author

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.

Copy link
Member

@NiLuJe NiLuJe Feb 5, 2024

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 ;).

Copy link
Member

@NiLuJe NiLuJe Feb 5, 2024

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...

-- book info
self:registerModule("bookinfo", FileManagerBookInfo:new{
dialog = self.dialog,
document = self.document,
ui = self,
})

;)

Copy link
Member Author

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

Copy link
Member

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 ;).

Copy link
Member Author

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.

Copy link
Member

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 ;).

Comment on lines -65 to -66
-- try to stay on current page
local select_number = nil
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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:

--[[
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 :)

@poire-z
Copy link
Contributor

poire-z commented Feb 5, 2024

Two ideas:

Thanks for the details (worth adding to the first post when you open a PR so the discovery is made easier :).
(I'm sure your ideas are good, and I sure can be lazy, so "trusting you" from me means "I can trust you and keep being lazy because I know I can trust you" :))

@hius07
Copy link
Member Author

hius07 commented Feb 6, 2024

Still hesitating with the name.
My self.bookinfo is a bridge between FM/Reader/Hist/Coll that use bookinfo for a module name and doc_props for book props, and CoverBrowser that uses bookinfo for cached book info (with additional fields like has_cover or ignore_cover that are absent in props).
So self.bookinfo can be

self.bookinfo = file_manager.coverbrowser and file_manager.coverbrowser:getBookInfo(file)

or
local props = doc_settings_or_file:readSetting("doc_props")
self.bookinfo = FileManagerBookInfo.extendProps(props, file)

@hius07 hius07 merged commit b8090c6 into koreader:master Feb 7, 2024
3 checks passed
@hius07 hius07 deleted the min-doc-settings branch February 7, 2024 08:35
@poire-z
Copy link
Contributor

poire-z commented Mar 19, 2024

Random hijack to mention some issue, not sure it's related to this PR, but maybe, or to some similar one.

  • File browser set to detailed list.
  • Open a book (I have "Start with last book")
  • Go to File browser (with the top menu icon)
  • Long-press on any book in this first shown File browser page: the dialog misses "Refresh cached book info" and "Ignore cover/metadata".
  • Now, just swipe to the next File browser page, and back to that initial page.
  • Long-press on any book in this same File browser page: the dialog now has "Refresh cached book info" and "Ignore cover/metadata".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants