Why is FEventTypeChildAdded getting called for all found children, not just added children?
m_firebaseRef = [[Firebase alloc] initWithUrl:fullChatPath];
FQuery* messageListQuery = [m_firebaseRef queryLimitedToNumberOfChildren:100];
[messageListQuery observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
NSLog( @"Name %@ with %d children.", snapshot.name, snapshot.childrenCount );
for( FDataSnapshot *child in snapshot.children )
[self addFirebaseSnapshotToCache:child andNotifyObservers:NO];
[self addFirebaseSnapshotToCache:nil andNotifyObservers:YES]; // Notify everything was added
// What kind of stinks is that I have to go through multiple passes of the data because FEventTypeChildAdded is triggered every time,
// a list is loaded as opposed to only being triggered for new nodes being added!
[messageListQuery observeEventType:FEventTypeChildAdded andPreviousSiblingNameWithBlock:^(FDataSnapshot *snapshot, NSString *prevNodeName) {
[self addFirebaseSnapshotToCache:snapshot andNotifyObservers:YES]; // Notify if something new was added
}];
}];
It seems like since the children have already been loaded that the inner observeEventType should only be called when new children are added. However, it is being called for all children in the queried node.
The addFirebaseSnapshotToCache will output a string with "Added" if it was a new node or "Exists" if it was an existing node. You can see from the output it is having to go though the data twice.
Here is the example output:
Name Live with 15 children.
Added = FLS3 (G:1386838476): Test
Added = FLS3 (G:1386838476): Hello, I think this will work just fine
Added = FLS3 (G:1386838476): 12345678901234567890123
Added = FLS3 (G:1386838476): 12345678901234567890123
Added = FLS3 (G:1386838476): How long of a text message
Added = FLS3 (G:1386838476): Let see how will this do?
Added = FLS3 (G:1386838476): Hello, this is a really long message to test
Added = FLS3 (G:1386838476): This is another really long test of characters in
Added = FLS3 (G:1386838476): WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
Added = << FLS4 >> (G:1386838660): test
Added = FLS3 (G:1386838476): Test back
Added = FLS3 (G:1386838476): Message #12
Added = FLS3 (G:1386838476): Ok
Added = FLS3 (G:1386838476): Test again
Added = FLS3 (G:1386838476): Wow it works
Notify of Changes
Exists = FLS3 (G:1386838476): Test
Exists = FLS3 (G:1386838476): Hello, I think this will work just fine
Exists = FLS3 (G:1386838476): 12345678901234567890123
Exists = FLS3 (G:1386838476): 12345678901234567890123
Exists = FLS3 (G:1386838476): How long of a text message
Exists = FLS3 (G:1386838476): Let see how will this do?
Exists = FLS3 (G:1386838476): Hello, this is a really long message to test
Exists = FLS3 (G:1386838476): This is another really long test of characters in
Exists = FLS3 (G:1386838476): WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
Exists = << FLS4 >> (G:1386838660): test
Exists = FLS3 (G:1386838476): Test back
Exists = FLS3 (G:1386838476): Message #12
Exists = FLS3 (G:1386838476): Ok
Exists = FLS3 (G:1386838476): Test again
Exists = FLS3 (G:1386838476): Wow it works
How should this be constructed to only make one pass thought the data while also allowing for new entries to be observed?