Skip to content

Conversation

Etienne-bdt
Copy link
Contributor

Description

Added sorting to the non primary images of a stack.

Since the mobile version behaves differently, the first one is extracted then the rest is sorted and both list are then reconcatenated.

This change addresses the issue of stack images ending up in a seemingly random order upon stacking.

Fixes #16250

How Has This Been Tested?

Stacks were made on 7 images with different dates, on both mobile and web version.

Stacks were created using increasingly recent dates (first one is the oldest file) and also using not the oldest as the first one to ensure it remained first after sorting on both mobile and web version

  • Stack more than 3 images, the first selected becomes the primary one

  • Navigate to stacked image

  • Confirm that the primary image remains first

  • Other images should be sorted by file creation date

  • Same test as above but selecting a file that is not the oldest or most recent of the stack, it should become the first in the stack viewer while the others are sorted

Screenshots (if appropriate)

File creation dates are as follow :

  • Dog : 2023/06/10 (selected first)
  • Monkey : 2021/04/06 - 10:17 am
  • Bread : 2021/04/06 - 11:16 am

web_stack
mobile_stack

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services)

@alextran1502 alextran1502 requested a review from mertalev March 3, 2025 16:24
@mertalev
Copy link
Member

mertalev commented Mar 3, 2025

Some of the server's asset repository methods also have stack relations and need to be updated to reflect the change. I don't like how the ordering is handled in the mobile app and would have liked it to be handled in the DB query. If it's ordered in one direction, then it should be possible to order it the other direction as well, no?

@mertalev
Copy link
Member

mertalev commented Mar 3, 2025

This is the query:

Future<List<Asset>> getStackAssets(String stackId) {

@Etienne-bdt
Copy link
Contributor Author

Thank you @mertalev , it works like a charm now !

@mertalev
Copy link
Member

mertalev commented Mar 3, 2025

Nice! Once the asset repo queries are updated, this PR should be good to go.

@Etienne-bdt
Copy link
Contributor Author

Reverted a change when sorting in the asset queries, I will look into it in more details tomorrow

@Etienne-bdt
Copy link
Contributor Author

Nice! Once the asset repo queries are updated, this PR should be good to go.

I took a look at the server asset repositories but when querying an asset by ID you only have the stack Id, the primary assetId and the asset count, not the assets of the stack themselves. Is it really necessary to add ordering in the asset repository? I might be missing a query somewhere, but I don't know.

@Etienne-bdt
Copy link
Contributor Author

Hey @mertalev , haven't been able to work on this PR recently but now I've got some time.
I've looked at the OpenAPI docs and all instances where I found a stack relation. They were squashed to give only the assetCount, I did not find one where assets needed to be sorted as they did not appear in the stack part of the server's response (just the Id, assetCount and primaryAssetId)

@mertalev
Copy link
Member

So for example, getByIds in the asset repository can return the stacked assets for each asset. I'm not sure which of those calls are for API responses and which are for internal server jobs. Ideally, it would only sort for the former since the internal usages don't really care about the order.

@Etienne-bdt
Copy link
Contributor Author

Yeah that makes sense, but from what I can see in the code, the assets are squashed in the DTO anyway.

Or we could add them back in the Stack Response with

  return {
    id: entity.stack.id,
    primaryAssetId: entity.stack.primaryAssetId,
    assets: entity.stack.assets,
    assetCount: entity.stack.assetCount ?? entity.stack.assets.length + 1,
  };

In which case it would be useful to sort them as they would appear back in the API query

@zackpollard
Copy link
Member

Hey, I am going to close this for now due to it being stale for quite a long time. If you still have time to fix this and have more questions please feel free to comment on this PR still and we can have it re-opened 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong order when stacking photos.
5 participants