CoverBrowser: fix getting cached info#10346
Conversation
| pages, percent_finished, status, has_highlight = unpack(self.menu.cover_info_cache[self.filepath]) | ||
| pages = self.menu.cover_info_cache[self.filepath][1] | ||
| percent_finished = self.menu.cover_info_cache[self.filepath][2] | ||
| status = self.menu.cover_info_cache[self.filepath][3] | ||
| has_highlight = self.menu.cover_info_cache[self.filepath][4] |
There was a problem hiding this comment.
May be to avoid 4 similar lookups:
local cached_info = self.menu.cover_info_cache[self.filepath]
pages = cached_info[1]
percent_finished = cached_info[2]
...(Also, I have a vague memory @NiLuJe may have had some other (shorter?) solution about intermediate nil values - does that ring a bell ?)
There was a problem hiding this comment.
That would be table.pack + unpack.
As long as the original table has been packed via table.pack, it can contain intermediate nils and unpack will handle it.
(NOTE: That's because we patch LuaJIT to enable Lua 5.2 semantics for table.pack, for folks trying to reproduce at home with a bog-standard LuaJIT build).
There was a problem hiding this comment.
Looking at CoverMenu:updateCache, that would be perfectly applicable there ;).
|
Another way is to assign |
|
So, I'm fine with using |
diff --git a/plugins/coverbrowser.koplugin/covermenu.lua b/plugins/coverbrowser.koplugin/covermenu.lua
index db069c4e0..534d1c859 100644
--- a/plugins/coverbrowser.koplugin/covermenu.lua
+++ b/plugins/coverbrowser.koplugin/covermenu.lua
@@ -61,7 +61,7 @@ function CoverMenu:updateCache(file, status, do_create, pages)
status = summary and summary.status
local highlight = doc_settings:readSetting("highlight")
local has_highlight = highlight and next(highlight) and true
- self.cover_info_cache[file] = {pages, percent_finished, status, has_highlight}
+ self.cover_info_cache[file] = table.pack(pages, percent_finished, status, has_highlight)
else
if self.cover_info_cache and self.cover_info_cache[file] then
if status thenFeels pretty simple to me ;o). |
Ok :) (I didn't look :/) |
Doesn't work. It produces the table: {
[3] = "abandoned",
n = 4
} --[[table: 0x47cdc9d0]]
But then dummy, percent_finished, status = table.unpack(self.menu.cover_info_cache[self.filepath])returns |
|
What's the actual input in that test? |
|
nil, nil, "abandoned", nil |
|
Huh. I'd forgotten to test this with more esoteric
|
|
May be this small fix can appear in 2023.04, together with #10350. |
|
Go ahead and merge if you feel it's no risk. |
Some values of the cache array can be
nil.This change is