BUG: Ineffecient way of getting images
Is there an existing issue for this?
- [x] I have searched the existing issues
What happened?
Where : backend/app/database/images.py
What happened ? : db_get_all_images fetches raw rows (potentially multiple per image due to joins) and iterates in Python to group tags into images_dict.
What should be : Use GROUP_CONCAT in the SQL query to aggregate tags per image ID in the database layer, returning one row per image.
Why?: Python iteration over 100k+ rows is significantly slower than C-based SQLite aggregation.
Record
- [x] I agree to follow this project's Code of Conduct
š Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)
Hi maintainers, Iām interested in working on this issue and have gone through the related code. Please let me know if I can take this up. Happy to discuss the approach first.
Hi @rohan-pandeyy and maintainers! š
I would love to work on this performance issue if it is still available.
I've analyzed the query in db_get_all_images() inside backend/app/database/images.py and proposed the following fix:
- Update the SQL query to aggregate tags in the database layer using
GROUP_CONCAT(m.name, ',')and grouping byi.id. - This eliminates duplicate rows returned by the JOIN and removes the necessity for the Python grouping loop, speeding up retrieval significantly.
Could you please assign this issue to me? Thanks!
@rohan-pandeyy can you assign this issue to me?