Im uncertain of the expected behaviour of the collection listener - does anyone know? It seems ... broken? #5514
Replies: 2 comments
-
I suspect I might know the answer to this. lets say my schema has many entities in it that all have a 1:1 relationship with something common, like a person example: I have collections of Pets, Toys, Books and each has a relationship with a Child, and the relationship is recorded in the Pet, Toy or Book .... Pet.child , Toy.child and Book.child What happens if I update the entire Pet just to change the Pets name...- rather than just PATCH the pets name, I am PUTing the entire Pet, including the unmodified child. will Realm consider that the child has been modified because it has been written? Then I suspect that the child, being considered modified, will be updated in every Pet, Toy or Book that also has a relationship with this child.... All because I changed the name of a single Pet. This would account for the type of change listener events that Im seeing |
Beta Was this translation helpful? Give feedback.
-
@kneth would you be able to comment on the above? thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi, Im using 11.5.1 and have been using realm for a few years now. Our app relies on collection listeners heavily - to update the UX from user activity and when syncing data from the backend, etc...
I always thought I knew how realm collection listeners worked, and the app seemed to work as expected....until recently it has been lagging more and more as users handle more data. I have traced the lag to the behaviour of the collection listeners firing too frequently and for spurious reasons, causing the app to be constantly updating itself for no reason.
So much for context. Here is my assumption of how they work. Lets say I have a table of 1000 widgets and I have some results which filter them - perhaps the results are 'all the red widgets', of which there are 10
Q1) attaching a listener to this result set, I would expect it to trigger only if the list of filtered results (the 10 red widgets) changed. If a widget in the DB was added/modified/deleted that was not red, I would not expect my listener to fire because ..who cares? it isnt going to affect my results. Is my assumption correct?
Q2) My other question is more about my observation of the changes being reported by the listener(s) in our app - they seem to be firing a lot and with nonsensical changes being reported - 100s or 1000s of modifications in the changes parameter being reported , triggered by database changes that have nothing to do with those collections!
Whatever we are doing wrong, its really starting to hurt us, so any detailed information on how to use listeners - how they really work and best practices etc...? would be much appreciated. Also, is there a chance that they are broken? Im happy to help diagnose any issues.
cheers
Steve
Beta Was this translation helpful? Give feedback.
All reactions