Collections: search in book content#13139
Conversation
|
Mhhh, not fond of having that. I also have no real idea of the possible side effects with crengine with calling loadDocument (without render) and half loading it: |
It is.
Can be disabled if Collections are opened over reader. |
Sounds quite fast really, in the sense that maybe the actual searching doesn't add much on top of the opening. |
|
In the worst scenario (string not found) it took about 2.5 min to scan a mixed collection of 90 books (pdf, epub, fb2, fb2.zip). |
If a collection content search has been done, then any book opened and closed, then the next search causes CRE warning "cached rendering is invalid" in crash.log for books in the collection. |
You mean opened and closed as book opened by the user for rendering and reading ? In which case, I guess it's normal: your search loadDocument would save a cached with no or default rendering properties saved - and when the book is opened for reading, a rerendering may happen, and the cache saved with the rendering props - and on next search loadDocument, these don't match the defaults.
If the warning happened on real user book opening, it should stay.
Well, you could do that, but you will end up with a I still think this PR is a bad idea :) the code is small, so you may add it - but let the user leave with the limitations (slow, no cache, just found=true/false), he probably won't use it once he sees how not really helpful it is, so no need for us to maintain another cache and risk cache/rendering issues with real book openings. |
|
CRE cache really speeds up searching. Opening the Reader invalidates it, but anyway it is useful for several consecutive searches, I'd like to keep it. Searching the library for a string in books is a frequent request. Yes, it's slow without indexing, but it works. |
That's fine, but does that imply the opposite is true as well? That seems more bothersome. |
|
Fair point. |
|
As far as I can see, "search in content" doesn't affect the main CRE cache. Reopening a book in Reader after "search in content" of this book doesn't require rerendering, the main cache remains good. |
Feels like luck :) and you mentionned you have had some CRE WARNING previously. Anyway, this feels too risky.
|
|
All search is under |
OK, so this might solve my 2. and avoid messing with the current crengine (even if no book is open, we may have crengine loaded with our default or user settings we don't re set on further openings).
OK, but you don't want to mess with the cache of any previously open book, and have strage stuff (or cache rendering is invalid, or even the DOM could be bad if you don't loadDocument with the same flat/book/web render mode). |
|
Sorry, I didn't mention. I'm thinking about the search cache destiny. |
|
CRE cache is not created in Anyway, I decided to disable the cache in search. The cache becomes invalid on opening the Reader, i.e. it does not live long. Searching in the whole library will cause huge storage writing of cache files for all books, not good. |
| if document.loadDocument then -- CRE | ||
| if not self.is_cre_cache_disabled then |
There was a problem hiding this comment.
Suggested comment:
-- We will be half-loading documents and may mess with crengine's state.
-- Fortunately, this is run in a subprocess, so we won't be affecting the
-- main process's crengine state or any document opened in the main
-- process (we furthermore prevent this feature when one is opened).
-- To avoid creating half-rendered/invalide cache files, it's best to disable
-- crengine saving of such cache files.
(Looks like you went back to comment-less coding :) there's not a single one in this PR :/)
|
Sad figures, average per book: |
|
Reduced to 3.0 s. |
|
3.0 s is an average time for a mixed library. |
| if is_cre_cache_disabled then | ||
| require("document/credocument").cacheInit() | ||
| end |
There was a problem hiding this comment.
If I understand it right, here we are in the main process.
You will set is_cre_cache_disabled=true in isFileMatch(), which is run in the subprocess. So, the is_cre_cache_disabled in the main process will not be affected: the 2 processes are independant and don't share any variable/memory.
You don't even need to re-enable the cache: once the subprocess dies, it's gone, whatever the state of things is, we don't care. The main process never gets it disabled.
|
Thanks. If engine has been inited before search, the cache is affected by the search, need to restore. EDIT: but it's another cache. Looking into it. EDIT2: main CRE cache is not affected by the search, I'm reverting last changes. |
|
Reverted. The crash with DocCache occurred because I deleted the whole .cache folder with the latest page cached images: koreader/frontend/apps/reader/readerui.lua Lines 820 to 821 in 89a24da By the way, we do not use these cached images for cre documents but create them. |
| function CreDocument.disableCache() | ||
| cre = cre or CreDocument:engineInit() | ||
| cre.initCache("", 0, true, 40) | ||
| end |
There was a problem hiding this comment.
You plan to use this for other things ?
Depending on the need, other use cases may want to use other parameters, so I'd somehow like to have that in the call site (like we do in the other places we tweak it).
Anyway, if keeping it, add a comment:
-- To be used only when in a subprocess to not interfere with opened books caches
Somehow, I don't have any, and only saw them (ie. koreader/cache/40f7e63bd12a22cf8b7640b81b16c7fa)) when I open a PDF. |
|
DocCache is not created by credocument, nothing is written when ReaderUI calls koreader/frontend/document/doccache.lua Lines 60 to 63 in 89a24da (I haven't looked into .cache folder for a while, maybe some cached pages occurred there during my experiments. In any case, I cannot reproduce the crash of DocCache anymore) |
|
@poire-z happy with it? |
|
Not really, I still think it is a bad idea - but as it's limited to Collections, hopefully we won't have much feedback and issues, so go ahead merging. |
Rather slow, average about 1.5 s per book on Kindle Voyage.
This change is