feat(mobile): cancel BlockOperation in iOS RemoteImageImpl#27522
Closed
LeLunZ wants to merge 1 commit intorefactor/ios-image-requestfrom
Closed
feat(mobile): cancel BlockOperation in iOS RemoteImageImpl#27522LeLunZ wants to merge 1 commit intorefactor/ios-image-requestfrom
LeLunZ wants to merge 1 commit intorefactor/ios-image-requestfrom
Conversation
8e6aecd to
913e8a0
Compare
Collaborator
Author
|
Closing this for now as the base PR won't get merged as #27672 exists now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Previously we could have queued a BlockOperation, cancelled it, and it would have launched a new thread just to check isCancelled.
With the changes in this PR the BlockOperation does internally in its start method see that the request got cancelled and just aborts launching a new thread.
I made the BlockOperation a part of the RemoteImageRequest and also cancel it incase request.cancel is called.
The kind of annoying part: we need another lock because we add the BlockOperation in the request thread, and read it from the main thread to call cancel on it.
I think conceptually this is cleaner, but performance wise I didn't see any positive/negative impact when comparing request/cancellation timings.
I also thought about just creating an empty BlockOperation in the main thread when creating the request, but then we would have to call operation.addExecutionBlock later. I think the whole BlockOperation is thread safe so this shouldn't be a problem. But I am then not sure what kind of lock they are using internally and that could be anything (possibly worse in performance than the UnsafeLock).
(Also removed id property from RemoteRequest as this wasn't used anywhere)
How Has This Been Tested?
Checklist:
src/services/uses repositories implementations for database calls, filesystem operations, etc.src/repositories/is pretty basic/simple and does not have any immich specific logic (that belongs insrc/services/)Please describe to which degree, if any, an LLM was used in creating this pull request.