Skip to content

Enumerate edges inside enumerate with a same transaction behaviour  #255

@YaroTs

Description

@YaroTs

When the same method for edges enumeration is used inside its block, wrong data can get to enumeration cycle.

For example, the following code demonstrates incorrect behaviour: inner enumeration for edge with name EdgeCommandsToPlayers has Commands as destination collection (should be Players).

[[transaction relationshipExtension] enumerateEdgesWithName:EdgeCategoriesToCommands
            sourceKey:category.key
            collection:Categories
            usingBlock:^(YapDatabaseRelationshipEdge* edge, BOOL* stop)
            {
                     Command* command = [transaction objectForKey:edge.destinationKey inCollection:Commands];

                     NSInteger __block sumScore = 0;
                     [[transaction relationshipExtension] enumerateEdgesWithName:EdgeCommandsToPlayers
                             sourceKey:command.key
                             collection:Commands
                             usingBlock:^(YapDatabaseRelationshipEdge* edge1, BOOL* stop1)
                             {
                                  Player* player = [transaction objectForKey:edge1.destinationKey inCollection:edge1.destinationCollection];
                                  sumScore += [player.score intValue];
                             }
                     }];

                    command.score = sumScore;
                    [commands addObject:command];
            }];

Probably, it happens because Statement in such case is shared and is not properly cleared.

So, is it bug or "enumerate inside enumerate" pattern just shouldn't be used?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions