PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG: Ineffecient way of getting images

Open aniket866 opened this issue 10 months ago • 4 comments

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

aniket866 avatar Jan 31 '26 09:01 aniket866

šŸ‘‹ 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 :)

github-actions[bot] avatar Jan 31 '26 09:01 github-actions[bot]

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.

krishnasingh-09 avatar Jan 31 '26 13:01 krishnasingh-09

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:

  1. Update the SQL query to aggregate tags in the database layer using GROUP_CONCAT(m.name, ',') and grouping by i.id.
  2. 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!

DashratRajpurohit avatar Jul 17 '26 11:07 DashratRajpurohit

@rohan-pandeyy can you assign this issue to me?

RounakKumarAgarwal avatar Nov 15 '26 10:11 RounakKumarAgarwal