mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
fetchAll in ListPublisher observer doesnt get new data #417
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @imrobbyrc on GitHub (Jul 27, 2023).
hi @JohnEstropia, i have some problem about corestore observer, can you help me?
this my method when fetch data from server and save it into database
and i add new observer in viewcontroller to notify when variant get updated, so i will fetch all groups data, but groups data is not get the latest one
@imrobbyrc commented on GitHub (Jul 27, 2023):
the result between fetchAll between fetchAll+ Where is different, all data should have isActive = true, but when i use where clause it only return 2 data, i have 3 active data with fetchAll only
@JohnEstropia commented on GitHub (Jul 28, 2023):
Why do you observe on
variantPublisherbut fetch different objects inside the observer handler? Your observer handler will run only on the changes affecting whatever predicate you assigned tovariantPublisher, so you should be using thepublisher.snapshotpassed through the observer closure.@imrobbyrc commented on GitHub (Jul 28, 2023):
thanks for reply @JohnEstropia, i fetch different objects because variant have relation with groups, i need to know what groups that available for new data. i can use
publisher.snapshot, but i need to iterrate all variants to get correct group@JohnEstropia commented on GitHub (Jul 28, 2023):
Your
Variantpublisher will not be notified even if any of theirGroups are updated. You need to "ping" something in yourVariantproperties to update when theirGroupchanges. Something like alastGroupUpdateDate@imrobbyrc commented on GitHub (Jul 28, 2023):
even i update groups in

VariantImportableUniqueObjectprotocol, myVariantpublisher will not be notified?@imrobbyrc commented on GitHub (Jul 28, 2023):
if i change my publisher closure to this, it will get a correct data instead of i use
.where(\._isActive == true)@JohnEstropia commented on GitHub (Jul 28, 2023):
Yes, because the
Variant.groupinstances do not change, which means theListPublisher<Variant>will not have a difference.I'm not sure how the
fetchAllpredicate is related to this observer and how it's behaving different depending on the predicate. Can you show what your predicate is forvariantPublisher?@JohnEstropia commented on GitHub (Jul 28, 2023):
You're also using
notifyInitial: truewhich will run the closure immediately. Are you sure that you are looking at the closure after the transaction?@imrobbyrc commented on GitHub (Jul 28, 2023):
i see, thats why observer doesnt get notified. thankyou
sure, this my variantPublisher code, just fetchAll and sorting it

@imrobbyrc commented on GitHub (Jul 28, 2023):
i think the problem is not
notifyInitial: true, because in first load i got a correct data, data will be break if i trigger variant update by using pull to refresh@JohnEstropia commented on GitHub (Jul 28, 2023):
I see. You should also be careful because sorting with relationship keys only work on the initial list, but not on updates. In general you should avoid relying on relationships when it comes to ListPublisher (NSFetchedResultsController) predicates because they are only reevaluated one level from the original Entity type
@imrobbyrc commented on GitHub (Jul 28, 2023):
oke @JohnEstropia thanks for reminded me, do we have utilities for combine two observer in coreStore?
@JohnEstropia commented on GitHub (Jul 28, 2023):
There's no performant way to observe on relationships (i.e. foreign table) so my recommended approach would be to add a private field to
Variantthat your imported entity can update everytime theGrouprelationship is imported from it.@imrobbyrc commented on GitHub (Jul 28, 2023):
i see thankyou @JohnEstropia , i will research new approach before going to use your suggestion