Add Combine-based Core Data resolver #110
Open
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.
Have you considered combine for handling non sendable core data types?
Key points
NSFetchRequest
with SELF IN %@ so filtering, sorting, and optional prefetching happen in the persistent store.DispatchQueue.main
by default) and supports optional debouncing of ID changes.flatMap
innerFuture
completes or is discarded as soon as its Core Data work finishes.Notes for maintainers
Thread confinement
context.perform { … }
.deliverOn
(default.main
). If you change the scheduler, ensure UI subscribers still hop to main.“Best-effort” semantics
RemoveDuplicates vs debounce
removeDuplicates
and relying on a smalldebounce
instead.Fetch strategy
NSFetchRequest
withSELF IN %@
so sorting/prefetching can be done by the store.IN
lists (thousands of IDs) — consider chunking (e.g. 500–1000 IDs) and concatenating results.Sorting
sortDescriptors
are pushed into the fetch (better than sorting in memory).sortDescriptors
; instead, reorder results against the incoming IDs post-fetch.Prefetching
prefetch
parameter and setrequest.relationshipKeyPathsForPrefetching = [...]
to avoid a wall of faults.Error handling
Never
-failing by design (errors map to[]
). If you need visibility for diagnostics, consider logging the caughterror
(e.g. os_log) or expose a secondary error publisher.Context type
weak
isn’t useful here.receive(on:)
to the main queue for UI.Model mismatches
T.entity().name
is nil or not in the model, we currently emit[]
. You may prefer throwing or surfacing an assertion in debug.Cancellation
flatMap
innerFuture
is short-lived and will not retain work beyondperform { … }
.