-
Hi! I'm getting some unexpected results from some The observers in question are in my TimelineSegment - the ones created in updateItems(from items: [TimelineItem]). What I'm seeing is Oh, relevant other source file: TimelineItem I'm getting console logging like:
Which showing that the sink() has fired on every TimelineItem, even though only one LocomotionSample was INSERTed, and assigned to one TimelineItemBase. The sample counts in the sink() fires are correct - the correct samples are there. It's just that the observers are firing for unrelated INSERTs. I thought it might be use of . I do have some TRIGGERs that fire on So I'm kind of stumped. It's possible I'm going to end up dumping this whole approach/optimisation. It's just an experiment at this stage. But figured I should at least first find out why it's not working, before throwing it in the bin 😉 Any advice much appreciated! Thanks 🙏🏼 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Hello @sobri909, You'll better understand the behavior of this For example: ValueObservation
.trackingConstantRegion(item.base.samples.fetchAll)
.print("Sample observer for item \(item.id)") In particular, you'll know what is the tracked region, as well as the updates that trigger the observation. Coupled with SQL tracing, this is your ultimate debugging tool. Please see the linked docs for more information, as well as the Why is ValueObservation not publishing value changes? FAQ. |
Beta Was this translation helpful? Give feedback.
-
Another thread, in the same discussion, about another topic: it looks like you are creating multiple observations, one per item. Take care that this might not scale, performance wise. Generally speaking, the number of observations run by an application should be bounded. In your particular case, the tracked requests, You will see those tracked regions when you call Very likely, all those observations share the same tracked region, and are all triggered together. This does not match the precise observation firing you might expect. We're dealing with SQLite limitations, here - GRDB can't be more precise 🤷♂️ Anyway. Maybe you'd better run one single observation for all items, and perform your own dispatching, item by item, at the application level. |
Beta Was this translation helpful? Give feedback.
-
Ah, I should've known you'd have handy debug methods! Nice! I'm seeing:
The same for all of them. So looks like they're all firing on the whole table as a region?
Sounds like it!
Yeah, I was kind of expecting to run into that. I haven't settled on the Correct or Best way to do this particular optimisation yet, and this particular approach already came with a few red flags. But I figured I should still try, even if just to eliminate it conclusively. With new LocomotionSamples being created potentially every 2-6 seconds for many hours of the day, I have to step super carefully. The optimisations I went for in old LocoKit were great for energy efficiency, but created many nightmares for my sanity. This time I'm hoping to do better 😏 In old LocoKit I implemented TimelineSegment as a |
Beta Was this translation helpful? Give feedback.
-
I think I've answered my own question about TransactionObserver, by reading the docs. heh So yeah, I'd be able to filter by table, and insert/delete/update, but beyond that I'm guessing SQLite doesn't offer us any more toys? |
Beta Was this translation helpful? Give feedback.
Another thread, in the same discussion, about another topic: it looks like you are creating multiple observations, one per item.
Take care that this might not scale, performance wise.
Generally speaking, the number of observations run by an application should be bounded.
In your particular case, the tracked requests,
item.base.samples
, do NOT define tracked database regions that precisely target one particular item (see the beginning of the ValueObservation Performance chapter for a description of what is tracked, exactly).You will see those tracked regions when you call
observation.print
.Very likely, all those observations share the same tracked region, and are all triggered together. …