Skip to content

feat(server): improve thumbnail relation and updating - #1897

Merged
alextran1502 merged 4 commits into
mainfrom
feat/server-thumbnail-relation
Mar 4, 2023
Merged

alextran1502 merged 4 commits into
mainfrom
feat/server-thumbnail-relation

Conversation

@michelheusschen

Copy link
Copy Markdown
Collaborator

Added albumThumnailAssetId foreign key to AssetEntity. It should actually be a composite foreign key to the linking table of assets and albums, but I've not done that due to quite some added complexity, because the linking table has to be defined explicitly.

Reworking AlbumService._checkValidThumbnail means we no longer need to pull all assets from the database in AlbumService.getAllAlbums and then those queries can be optimized further, which has recently been causing some performance bottlenecks.

Still WIP and haven't tested it beyond the basics

@vercel

vercel Bot commented Feb 28, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated
immich ⬜️ Ignored (Inspect) Mar 4, 2023 at 7:43AM (UTC)

@michelheusschen

Copy link
Copy Markdown
Collaborator Author

Changed the query for updateThumbnails a bit, it now runs in less than 0.1ms for 5000 assets and 5 albums when no updates are needed. Then if a thumbnail needs to be updated it adds about 2ms for every updated album.

To the migrations I've added a slightly modified version of the updateThumbnails query to allow comparing between uuid and varchar. The query probably won't do anything in 99% of cases, but I've added it to prevent any issues with converting to uuid and adding the foreign key.

@michelheusschen
michelheusschen marked this pull request as ready for review March 1, 2023 11:38
Comment thread server/apps/immich/src/api-v1/album/album-repository.ts

public async up(queryRunner: QueryRunner): Promise<void> {
// Make sure all albums have a valid albumThumbnailAssetId UUID or NULL.
await queryRunner.query(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the manual query for migration, not from the generated command, correct?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the query that gets generated by AlbumRepository.updateThumbnails() with one added ::varchar cast at the end. The query below this one is also custom, because the generated command removes and then re-adds the column which would result in data loss.

@jrasm91 jrasm91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alextran1502
alextran1502 enabled auto-merge (squash) March 3, 2023 22:46
@alextran1502

Copy link
Copy Markdown
Member

@michelheusschen Hi Michel, can you help fix the unit tests?

@alextran1502
alextran1502 disabled auto-merge March 4, 2023 06:04
@michelheusschen
michelheusschen force-pushed the feat/server-thumbnail-relation branch from 600434e to dbedb38 Compare March 4, 2023 07:37
@michelheusschen

Copy link
Copy Markdown
Collaborator Author

@michelheusschen Hi Michel, can you help fix the unit tests?

Unit tests are fixed. Rebasing went a bit wrong but I've sorted it out

@alextran1502
alextran1502 merged commit bdf35b6 into main Mar 4, 2023
@alextran1502
alextran1502 deleted the feat/server-thumbnail-relation branch March 4, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants