AOSSIE-Org / AOSSIE-Org/PictoPy

perf: avoid full table scan in toggle-favourite endpoint

オープン
#1,223 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
283
フォーク
679
平均マージ
7日 2時間
マージ済み PR(30日)
3

説明

### What happened?

In `backend/app/routes/images.py`, the `/toggle-favourite` endpoint fetches **all images** from the database just to retrieve the updated favourite status of a single image:
```python
image = next(
(img for img in db_get_all_images() if img["id"] == image_id), None
)
```

This is a full table scan on every toggle action. If a user has thousands of images, this is extremely slow and wasteful.

### Why this matters
- Poor performance at scale
- Unnecessary database load on every favourite toggle
- `db_get_all_images()` is an expensive query with JOINs

### Proposed fix
Add a `db_get_image_by_id(image_id)` function to `database/images.py` and use it instead of scanning all images.

### Expected behavior
The endpoint should fetch only the single toggled image using its ID.

I'd like to fix this if maintainers agree.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。