1

追加された子だけでなく、見つかったすべての子に対して FEventTypeChildAdded が呼び出されるのはなぜですか?

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
    }];
}];

子が既にロードされているため、新しい子が追加されたときにのみ内部のobserveEventTypeを呼び出す必要があるようです。ただし、照会されたノード内のすべての子に対して呼び出されています。

addFirebaseSnapshotToCache は、新しいノードの場合は "Added"、既存のノードの場合は "Exists" の文字列を出力します。出力から、データを 2 回処理する必要があることがわかります。

出力例を次に示します。

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

新しいエントリを観察できるようにしながら、データを1回だけ通過させるには、これをどのように構築する必要がありますか?

4

1 に答える 1