Skip to content

refactor(mobile): introduce image request registry on iOS #27486

Merged
mertalev merged 6 commits intomainfrom
refactor/ios-image-registry
Apr 5, 2026
Merged

refactor(mobile): introduce image request registry on iOS #27486
mertalev merged 6 commits intomainfrom
refactor/ios-image-registry

Conversation

@LeLunZ
Copy link
Copy Markdown
Collaborator

@LeLunZ LeLunZ commented Apr 3, 2026

Description

Base branch of this Pr is currently #27471

Currently LocalImageApiImpl and RemoteImageApiImpl each maintain their own mechanism for tracking inflight requests

  • Local used three DispatchQueues (assetQueue, requestQueue, cancelQueue) plus a raw [Int64: LocalImageRequest] dictionary, with manual add/remove/cancel static methods.
  • Remote used a raw os_unfair_lock held as a static var, with manual os_unfair_lock_lock/unlock calls around every dictionary access.

For me that just feels very inconsistent for the same "work".

Thats why I introduced Cancellable protocol and a generic RequestRegistry<T: Cancellable> that centralise all the request tracking together. Everything is done behind a UnfairLock which I think is the faster approach between locks, and queues.

In the RemoteImageApiImpl we can now remove the lock, and all manual lock/unlock calls as they are replaced by the registry.

In the LocalImageApiImpl we can remove the cancelQueue and requestQueue as both are handled by the lock in the registry.

Additional change:

removed assetQueue as NSCache is already thread safe.

How Has This Been Tested?

  • on an emulator

Checklist:

  • I have carefully read CONTRIBUTING.md
  • 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/)

Please describe to which degree, if any, an LLM was used in creating this pull request.

unfair lock implementation

@LeLunZ LeLunZ requested a review from mertalev April 3, 2026 13:16
@LeLunZ LeLunZ requested a review from shenlong-tanwen as a code owner April 3, 2026 13:16
@immich-push-o-matic
Copy link
Copy Markdown

Label error. Requires exactly 1 of: changelog:.*. Found: 📱mobile. A maintainer will add the required label.

@LeLunZ LeLunZ changed the title refactor(mobile): introduce request registry on iOS refactor(mobile): introduce image request registry on iOS Apr 3, 2026
Comment thread mobile/ios/Runner/Images/ImageRequest.swift Outdated
Base automatically changed from bugfix-27365 to main April 5, 2026 20:11
@mertalev
Copy link
Copy Markdown
Member

mertalev commented Apr 5, 2026

I updated the lock implementation to be a general utility and made it more type-safe. It has Mutex for guarding specific state and UnfairLock for more general cases that don't map cleanly to a single state.

@mertalev mertalev merged commit cd86a83 into main Apr 5, 2026
56 of 57 checks passed
@mertalev mertalev deleted the refactor/ios-image-registry branch April 5, 2026 22:55
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.

2 participants