Timestamp delay causing double firing of "child_changed"

471 views
Skip to first unread message

Jethro Bodine

unread,
Jul 20, 2016, 1:29:39 PM7/20/16
to Firebase Google Group
I'm writing data to a location where I want to know when a child is modifed. 

The child data consists of a message and a timestamp as such - 
{locationOfChildChangedListener: {child(unknown_key): {"message":someText, "time":firebase.database.ServerValue.TIMESTAMP}}}

As the topic suggests, the callback function fires twice when I update the child location with the message/time object. And it looks like its because of a result of the timestamp beig delayed. Any suggestions on this? is this a bug? or is it meant to operate that way and i'll have to use the client time to update the values simultaneously?

Thanks

Kato Richardson

unread,
Jul 20, 2016, 1:41:53 PM7/20/16
to Firebase Google Group
Hi Jethro,

So this occurs because we trigger the local event immediately (i.e. latency compensation) and then the server applies the real timestamp and sends back the value of the server time, which doesn't match the local value, and triggers another change event.

Ideally, you'd just handle this transparently--the change is just going to update the timestamp to be more accurate by what is likely milliseconds. So go ahead and apply it.

Is there some reason that the second update is problematic?

☼, Kato



--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/2096a55e-7819-4b66-a9ff-e4b0efc06e7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Jeffrey Kennedy

unread,
Jul 20, 2016, 1:49:08 PM7/20/16
to fireba...@googlegroups.com

It's problematic in this case because I'm adding items to a page on each trigger, so it looks like duplicates. I'll figure some workaround, but didn't know if it was meant to work that way.


You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/m3xci3wbzxE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Joe White

unread,
Jul 20, 2016, 1:57:41 PM7/20/16
to Firebase Google Group
[just another user] I would always recommend checking for duplicates whenever adding something that should not be duplicated to a list.  In this programming world, all sorts of things can go wrong ... particularly in other folks code (either because there is a bug or because we don't understand the exact side effects).

Kato Richardson

unread,
Jul 20, 2016, 2:01:10 PM7/20/16
to Firebase Google Group
Hi Jeffrey,

You should be using the child added event to add things to the page (not the updated event). This will naturally be called more than once.

☼, Kato


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages