Skip to content

refactor(mobile): iOS introduce ImageRequest base class with unified cancellation and finish helpers#27489

Open
LeLunZ wants to merge 1 commit intorefactor/ios-image-registryfrom
refactor/ios-image-request
Open

refactor(mobile): iOS introduce ImageRequest base class with unified cancellation and finish helpers#27489
LeLunZ wants to merge 1 commit intorefactor/ios-image-registryfrom
refactor/ios-image-request

Conversation

@LeLunZ
Copy link
Copy Markdown
Collaborator

@LeLunZ LeLunZ commented Apr 3, 2026

Description

After PR #27486, LocalImageRequest and RemoteImageRequest each still duplicated the same boilerplate: an isCancelled flag, a stored callback, a cancel() method, and identical malloc/vImage_Buffer blocks in their respective ImageApiImpl.

This PR adds the ImageRequest base class with:

  • Thread-safe cancellation, and guarantee that it is only cancelled once
  • cancel(): sets isCancelled, nil's the callback, calls onCancel(), then fires cancelledResult
  • onCancel(): empty hook for subclasses to cancel their underlying work (operation, URL task).
  • finish(with:): completes the request with any result.
  • finish(encoding:): allocates a raw pointer from Data, frees it if cancelled, otherwise completes with pointer + length
  • finish(cgImage:format:): takes format as inout so the caller's static var is passed by reference — only one copy occurs when forwarding to vImage_Buffer. Frees the buffer if cancelled

The Remote and Local ImageRequest implement the Base class.

Behaviour changes that this PR includes:
the pigeon callback is now called directly when setting isCancelled to true. Not when the thread runs and sees that isCancelled is true and terminates the operation.
I think we can already communicate to flutter that the operation is cancelled and we don't have to wait on the thread to actually return or?

How Has This Been Tested?

  • on an iOS simulator

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.

/

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

immich-push-o-matic bot commented Apr 3, 2026

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

lock.withLock { _isCancelled }
}

init(callback: @escaping (Result<[String: Int64]?, any Error>) -> Void) {
Copy link
Copy Markdown
Collaborator Author

@LeLunZ LeLunZ Apr 3, 2026

Choose a reason for hiding this comment

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

@mertalev Regarding this being nullable, thats how the pigeon communication is typed. null values means cancellation.
Thats also the same on main. See here

@LeLunZ LeLunZ changed the title refactor(mobile): introduce ImageRequest base class with unified cancellation and finish helpers refactor(mobile): iOS introduce ImageRequest base class with unified cancellation and finish helpers Apr 3, 2026
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.

1 participant