Future optimisations #1483

Closed
opened 2026-02-20 00:09:52 -05:00 by deekerman · 1 comment
Owner

Originally created by @bo0tzz on GitHub (Oct 19, 2023).

This is a high-level issue to collect optimisations to Immich that we want to make in the future. PRs to resolve any of these are very welcome, but please check in with the maintainers first if you are going to do significant amounts of work.


Solved issues

Job Queries (#17622, #17623, #17631, #17652, #17745, etc.)

Currently, there are some repository methods that are shared between jobs and API responses. I believe there are some database queries that unnecessarily load relations that are only required for a single use case, while the method is used for multiple. We should do some analysis to determine what repository methods are used by jobs vs API endpoints and potentially separate them out into separate. This would allow for less confusion/coupling in the future and make it possible to reduce loading unneeded relations.

Album Insertion (solved by #4603)

Currently, the logic to insert assets into an album works by first looping over every assetId that needs to be inserted to check if it's already in the album, before trying to insert only the assets that aren't. This can be optimised by INSERTing all the assets into the album while using ON CONFLICT DO NOTHING, so that assets already in the album are skipped. The asset IDs that were successfully inserted can be returned by the query using RETURNING assetId, so that the response format of addAssets can remain unchanged.

Access Control (#5223, #5290, #5315, #5329, #5775)

Currently the access control checks work on a per item basis. This can be improved by instead sending batched requests to the database when a list is provided. While not currently a performance issue from an app perspective, this optimization should decrease load on the database and would be a welcomed change.

Tag Insertion (#11980)

Currently, adding and removing assets from tags works very similar to how albums used to work, prior to PR #4516. This should be updated to work similar to the above proposal for album insertion.

Originally created by @bo0tzz on GitHub (Oct 19, 2023). This is a high-level issue to collect optimisations to Immich that we want to make in the future. PRs to resolve any of these are very welcome, but please check in with the maintainers first if you are going to do significant amounts of work. --- <details> <summary>Solved issues</summary> ### Job Queries (#17622, #17623, #17631, #17652, #17745, etc.) Currently, there are some repository methods that are shared between jobs and API responses. I believe there are some database queries that unnecessarily load relations that are only required for a single use case, while the method is used for multiple. We should do some analysis to determine what repository methods are used by jobs vs API endpoints and potentially separate them out into separate. This would allow for less confusion/coupling in the future and make it possible to reduce loading unneeded relations. ### Album Insertion (solved by #4603) Currently, [the logic to insert assets into an album](https://github.com/immich-app/immich/blob/5a7ef02387aea9db3774c8a60dc02663e57e973c/server/src/domain/album/album.service.ts#L150-L183) works by first looping over every assetId that needs to be inserted to check if it's already in the album, before trying to insert only the assets that aren't. This can be optimised by `INSERT`ing all the assets into the album while using [`ON CONFLICT DO NOTHING`](https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT), so that assets already in the album are skipped. The asset IDs that were successfully inserted can be returned by the query using `RETURNING assetId`, so that the response format of `addAssets` can remain unchanged. ### Access Control (#5223, #5290, #5315, #5329, #5775) Currently the access control checks work on a per item basis. This can be improved by instead sending batched requests to the database when a list is provided. While not currently a performance issue from an app perspective, this optimization should decrease load on the database and would be a welcomed change. ### Tag Insertion (#11980) Currently, adding and removing assets from tags works very similar to how albums used to work, prior to PR #4516. This should be updated to work similar to the above proposal for album insertion. </details>
Author
Owner

@jrasm91 commented on GitHub (Jun 19, 2025):

All these initial issues have now been completed

@jrasm91 commented on GitHub (Jun 19, 2025): All these initial issues have now been completed
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/immich#1483
No description provided.