Gallery - Initial load of images is slow
muss3000 opened this issue · comments
-
Platform: Ubuntu - 5.15.0-78-generic #85~20.04.1-Ubuntu
-
MythTV version: fixes/31
-
Package version: v31-0-154-gf8c59ee69d
-
Component: Images
What steps will reproduce the bug?
Populate the gallery with a large number of images structured across many directories. For example in my instance there are 125k images spread across a large structured subdirectory categorising images. The total directories are approximately 4800 in a tree structure. From this state then to reproduce this then it takes at least 5+ seconds to load the initial top level directories.
How often does it reproduce? Is there a required condition?
Every time
What is the expected behaviour?
Very little delay in loading content.
What do you see instead?
The intial load time exceeds 5 seconds and this gets worse as the gallery content increases. Mysql is performing a full table scan on gallery_files when identifying the initial root directory (ie gallery_files.dir_id = 1). This is coming from libs/libmythmetadata/imagemanager.cpp
The identified problem query is: -
SELECT * FROM gallery_files WHERE dir_id IN (1) AND hidden = 0 ORDER BY CASE WHEN type <= 3 THEN name END ASC, CASE WHEN type > 3 THEN name END ASC;
Additional information
A suggested fix to this is to add an index to gallery_files indexing the column dir_id
This is an example of the above query performs when the index is added
Wow. My gallery load time went from 20s to 0.5s. Thanks you.
Matthew, you'll need to delete the index you created before upgrading. I didn't add logic to check for the existence of the index before creating it.
No problem. Thanks for implementing it! Hopefully it improves others experience.
I didn't add logic to check for the existence of the index before creating it.
Is that not just a case of CREATE INDEX IF NOT EXISTS
rather than just CREATE INDEX
? Or perhaps CREATE OR REPLACE INDEX
?
I didn't add logic to check for the existence of the index before creating it.
Is that not just a case of
CREATE INDEX IF NOT EXISTS
rather than justCREATE INDEX
? Or perhapsCREATE OR REPLACE INDEX
?
As I recall, not if you are using MySQL (as is the default for one distro due to a "marketing agreement" (money)), where the IF NOT EXISTS is not supported.