[PR #2085] [MERGED] feature(mobile): Hardening synchronization mechanism + Pull to refresh #9366

Closed
opened 2026-02-05 14:03:27 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/immich-app/immich/pull/2085
Author: @fyfrey
Created: 3/25/2023
Status: Merged
Merged: 3/27/2023
Merged by: @alextran1502

Base: mainHead: dev/mobile-sync-fixes


📝 Commits (3)

  • 1d5ea56 fix(mobile): allow syncing duplicate local IDs
  • 731adf8 enable to run isar unit tests on CI
  • d332c78 serialize sync operations, add pull to refresh on timeline

📊 Changes

21 files changed (+654 additions, -250 deletions)

View changed files

📝 mobile/lib/main.dart (+1 -0)
📝 mobile/lib/modules/album/ui/album_thumbnail_card.dart (+1 -1)
📝 mobile/lib/modules/album/views/sharing_page.dart (+1 -1)
📝 mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart (+24 -22)
📝 mobile/lib/modules/home/ui/asset_grid/immich_asset_grid_view.dart (+20 -16)
📝 mobile/lib/modules/home/views/home_page.dart (+18 -0)
📝 mobile/lib/modules/login/providers/authentication.provider.dart (+0 -2)
📝 mobile/lib/shared/models/asset.dart (+93 -18)
📝 mobile/lib/shared/models/asset.g.dart (+122 -96)
📝 mobile/lib/shared/models/store.dart (+1 -1)
📝 mobile/lib/shared/providers/asset.provider.dart (+41 -55)
📝 mobile/lib/shared/services/asset.service.dart (+5 -8)
📝 mobile/lib/shared/services/immich_logger.service.dart (+11 -5)
📝 mobile/lib/shared/services/sync.service.dart (+97 -24)
📝 mobile/lib/utils/async_mutex.dart (+5 -0)
mobile/lib/utils/db.dart (+14 -0)
📝 mobile/lib/utils/migration.dart (+14 -1)
📝 mobile/test/asset_grid_data_structure_test.dart (+1 -0)
mobile/test/async_mutex_test.dart (+41 -0)
📝 mobile/test/favorite_provider_test.dart (+1 -0)

...and 1 more files

📄 Description

This PR tries to fix several issues with the new client database sync:

and adds pull to refresh on the main timeline:

You can refresh assets on the main timeline with the usual material design refresh gesture by pulling down. If you that twice (within 2 seconds after the first refresh finished), a full clean and reload is performed, i.e. all assets and albums are purged from the DB and re-synced from device and server.

Changes:

  • Removes the unique constraint on localId & deviceId: allows duplicates from web/cli or uploaded from the same mobile device with different users
  • syncing remote to local assets is updated to allow for duplicates: sort and compare by userId, deviceId, localId and modification time (to account for duplicates originating from edited files imported via CLI)
  • keeps backed-up assets as remote in teh database after deleting the local files on the device
  • Add AssetType to Asset
  • Adds a version setting to the database
  • Migrate client database: clears the assets in the client database once
  • No longer uses UTC when creating Asset (as Isar always returns dates in local time)
  • implements == and hashCode for Asset so that changes to the list of assets actually result in a re-render of the timeline
  • adjust log level of database errors
  • changes logging to async write (because you cannot run sync and async write operations in the same isolate at the same time)
  • adds some tests for the SyncService
  • serialize sync operations to guard against concurrency bugs
  • reworked onNewAssetUploaded

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/immich-app/immich/pull/2085 **Author:** [@fyfrey](https://github.com/fyfrey) **Created:** 3/25/2023 **Status:** ✅ Merged **Merged:** 3/27/2023 **Merged by:** [@alextran1502](https://github.com/alextran1502) **Base:** `main` ← **Head:** `dev/mobile-sync-fixes` --- ### 📝 Commits (3) - [`1d5ea56`](https://github.com/immich-app/immich/commit/1d5ea56f417ae8795724c5fcf2b2156ad2d94525) fix(mobile): allow syncing duplicate local IDs - [`731adf8`](https://github.com/immich-app/immich/commit/731adf8881dcf6de2a102f88842f546ed7b9a39a) enable to run isar unit tests on CI - [`d332c78`](https://github.com/immich-app/immich/commit/d332c78135fbfdf1fb2c9073b97a6a709b90552d) serialize sync operations, add pull to refresh on timeline ### 📊 Changes **21 files changed** (+654 additions, -250 deletions) <details> <summary>View changed files</summary> 📝 `mobile/lib/main.dart` (+1 -0) 📝 `mobile/lib/modules/album/ui/album_thumbnail_card.dart` (+1 -1) 📝 `mobile/lib/modules/album/views/sharing_page.dart` (+1 -1) 📝 `mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart` (+24 -22) 📝 `mobile/lib/modules/home/ui/asset_grid/immich_asset_grid_view.dart` (+20 -16) 📝 `mobile/lib/modules/home/views/home_page.dart` (+18 -0) 📝 `mobile/lib/modules/login/providers/authentication.provider.dart` (+0 -2) 📝 `mobile/lib/shared/models/asset.dart` (+93 -18) 📝 `mobile/lib/shared/models/asset.g.dart` (+122 -96) 📝 `mobile/lib/shared/models/store.dart` (+1 -1) 📝 `mobile/lib/shared/providers/asset.provider.dart` (+41 -55) 📝 `mobile/lib/shared/services/asset.service.dart` (+5 -8) 📝 `mobile/lib/shared/services/immich_logger.service.dart` (+11 -5) 📝 `mobile/lib/shared/services/sync.service.dart` (+97 -24) 📝 `mobile/lib/utils/async_mutex.dart` (+5 -0) ➕ `mobile/lib/utils/db.dart` (+14 -0) 📝 `mobile/lib/utils/migration.dart` (+14 -1) 📝 `mobile/test/asset_grid_data_structure_test.dart` (+1 -0) ➕ `mobile/test/async_mutex_test.dart` (+41 -0) 📝 `mobile/test/favorite_provider_test.dart` (+1 -0) _...and 1 more files_ </details> ### 📄 Description This PR tries to fix several issues with the new client database sync: - #2069 - #2063 - #2053 and adds pull to refresh on the main timeline: You can refresh assets on the main timeline with the usual material design refresh gesture by pulling down. If you that twice (within 2 seconds after the first refresh finished), a full clean and reload is performed, i.e. all assets and albums are purged from the DB and re-synced from device and server. Changes: - Removes the unique constraint on `localId` & `deviceId`: allows duplicates from web/cli or uploaded from the same mobile device with different users - syncing remote to local assets is updated to allow for duplicates: sort and compare by userId, deviceId, localId and modification time (to account for duplicates originating from edited files imported via CLI) - keeps backed-up assets as remote in teh database after deleting the local files on the device - Add `AssetType` to `Asset` - Adds a version setting to the database - Migrate client database: clears the assets in the client database once - No longer uses UTC when creating `Asset` (as Isar always returns dates in local time) - implements `==` and `hashCode` for `Asset` so that changes to the list of assets actually result in a re-render of the timeline - adjust log level of database errors - changes logging to async write (because you cannot run sync and async write operations in the same isolate at the same time) - adds some tests for the `SyncService` - serialize sync operations to guard against concurrency bugs - reworked `onNewAssetUploaded` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 14:03:27 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#9366