fix(files_reminders): reduce N+1 query issue for big folders#58288
fix(files_reminders): reduce N+1 query issue for big folders#58288salmart-dev wants to merge 1 commit intomasterfrom
Conversation
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
|
/backport to stable33 please |
|
/backport to stable32 please |
|
/backport to stable31 please |
|
I am wondering if it makes sense for CappedMemory cache to discard old entries… I am also a bit afraid that 30k entries in cache use a lot of memory |
That is what the current code is already doing. We insert by key, and while inserting we call |
|
Sorry, it wasn't clear ^^ Maybe CappedMemory cache should just stop discarding entries. When it's full, it serves current entries and stop adding new ones. |
But that still means then executing N-512 queries to load data for directories with N files, no? I'm thinking of two things:
|
come-nc
left a comment
There was a problem hiding this comment.
Yeah it’s the issue with the preloading strategy it means we need to keep the complete list of entries in memory, which may not always fit, or will eat up a lot of memory.
I would feel better if we could change the logic to instead use generators and stream each node through the plugins, one at a time. But I’m not sure that’s possible or easy with sabre/dav architecture, and also it’s not good either, because it would mean doing a DB request for each node which we do not want. So I’m not sure what’s the perfect solution.
We’d need that but with each plugin opening and keeping its DB request to fetch data one by one or something. (or batch by batch more realisticly)
I think doing this in a streaming fashion for all results is not possible as we'd depend on the order of access, which would mean that the DB query and the code must use the same scan order for nodes so that the properties are read in order from the DB. I think going by batches would be better, I'm just not sure how performant having all queries become I have some sabre/dav branch to allow getting the list of nodes that will need their properties loaded before the |
Summary
Increases the
CappedMemoryCachesize forReminderServiceto 30k.Context
OCA\FilesReminders\Dav\PropFindPluginpreloads reminders information for an entire collection during PROPFIND.ReminderServicehas acacheFoldermethod which uses aCappedMemoryCacheas cache. The problem is that the default size for this cache is512meaning that if a directory has more than 512 files inside we start getting cache misses and start querying the DB.What's worse is that once the condition hits, it always voids the pre-cached data and causes N+1 queries:
preloadCollectionstarts caching reminders for files in a directoryCappedMemoryCacheis reached, the information that was cached earlier is discardedChecklist
3. to review, feature component)stable32)