refactor(mobile): device asset entity to use modified time #17064
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4939
Fixes #6439 (haven't tested the iOS part of the issue, the issue in Android does gets fixed)
Description
The current hashing implementation of the app is follows:
AndroidDeviceAssetSchema
orIOSDeviceAssetSchema
This approach has issues, especially when the asset is modified in-place outside immich after hashed by the app. When the asset is modified in-place and the platform does not make changes to the
localID
of the edited asset, our current approach proceeds to reuse the hash, even when the hash of the actual file is modified. The PR fixes this by also storing the asset'smodifiedTime
to the entity and compare it during lookup to reuse the hash.The existing approach also relied on updating object references inside collections to pass the updated hash back to the caller. This makes it hard to reason about the code. This has been refactored to make the logic simpler and understandable.
Even when the
localId
fromAssetEntity
were Strings, we were using two different device asset schemas to store the hashes. One for android which converted the string IDs to int and the iOS that stored the string IDs directly. The PR refactors this to use a common entity namedDeviceAssetEntitySchema
. Migration handling is also added to move the hashes from the existing schemas to the new schemas.