将LinkedList保存到解析服务器

时间:2018-06-12 09:35:05

标签: objective-c linked-list parse-server

我正在尝试使用Parse PFObjects构建单链接列表。每个PFObject都有一个指向列表中 next 对象的指针。我可以在本地固定它们,但是在将它们保存到Parse Server时我遇到了问题。

问题从这里开始:

+ (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *)currentUser sessionToken:(NSString *)sessionToken;
    // This saves all of the objects and files reachable from the given object.
    // It does its work in multiple waves, saving as many as possible in each wave.
    // If there's ever an error, it just gives up, sets error, and returns NO;

当尝试保存列表中的第一个对象时,它将访问子对象(下一个对象)并尝试先保存该对象。由于子(下一个对象)也有一个指向列表中下一个对象的指针,因此这将继续发生,直到列表中的最后一个对象。

对于少量对象(&lt; 200)成功,但是一旦我们使用大量对象处理链接列表,这里就会出现崩溃:< / p>

/**
 Finds all of the objects that are reachable from child, including child itself,
 and adds them to the given mutable array.  It traverses arrays and json objects.
 @param node  An kind object to search for children.
 @param dirtyChildren  The array to collect the result into.
 @param seen  The set of all objects that have already been seen.
 @param seenNew  The set of new objects that have already been seen since the
 last existing object.
 */
+ (BOOL)collectDirtyChildren:(id)node
                    children:(NSMutableSet *)dirtyChildren
                       files:(NSMutableSet *)dirtyFiles
                        seen:(NSSet *)seen
                     seenNew:(NSSet *)seenNew
                 currentUser:(PFUser *)currentUser
                       error:(NSError * __autoreleasing *)error

deepSaveAsyncChildrenOfObject调用此方法来构建必须保存的子对象的NSSet。

@synchronized ([object lock]) {
            // Check for cycles of new objects.  Any such cycle means it will be
            // impossible to save this collection of objects, so throw an exception.
            if (object.objectId) {
                seenNew = [NSSet set];
            } else {
                if ([seenNew containsObject:object] && error) {
                    *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidPointer
                                                     message:@"Found a circular dependency when saving."];
                    return NO;
                }
// CRASH: Thread 160: EXC_BAD_ACCESS (code=2, address=0x70000fc80f38)
                seenNew = [seenNew setByAddingObject:object];
            }

            // Check for cycles of any object.  If this occurs, then there's no
            // problem, but we shouldn't recurse any deeper, because it would be
            // an infinite recursion.
            if ([seen containsObject:object]) {
                return YES;
            }
            seen = [seen setByAddingObject:object];

            // Recurse into this object's children looking for dirty children.
            // We only need to look at the child object's current estimated data,
            // because that's the only data that might need to be saved now.
            toSearch = [object._estimatedData.dictionaryRepresentation copy];
        }

因此,可以通过保存PFObject 而不保存其子项来避免这种情况,有什么办法可以做到这一点吗?或者是否有任何解决方法将链表保存到解析服务器,可能是使用Cloud Code,还是修改数据模型?

0 个答案:

没有答案