@@ -79,25 +79,6 @@ static void PFObjectAssertValueIsKindOfValidClass(id object) {
7979 PFParameterAssert (NO , @" PFObject values may not have class: %@ " , [object class ]);
8080}
8181
82- /* !
83- Checks if a class is a of container kind to be used as a value for PFObject.
84- */
85- static BOOL PFObjectValueIsKindOfMutableContainerClass (id object) {
86- static NSArray *classes;
87- static dispatch_once_t onceToken;
88- dispatch_once (&onceToken, ^{
89- classes = @[ [NSDictionary class ], [NSArray class ], [PFACL class ], [PFGeoPoint class ] ];
90- });
91-
92- for (Class class in classes) {
93- if ([object isKindOfClass: class]) {
94- return YES ;
95- }
96- }
97-
98- return NO ;
99- }
100-
10182@interface PFObject () <PFObjectPrivateSubclass> {
10283 // A lock for accessing any of the internal state of this object.
10384 // Guards basically all of the variables below.
@@ -111,9 +92,6 @@ @interface PFObject () <PFObjectPrivateSubclass> {
11192 // TODO (grantland): Derive this off the EventuallyPins as opposed to +/- count.
11293 int _deletingEventually;
11394
114- // A dictionary that maps id (objects) => PFJSONCache
115- NSMutableDictionary *hashedObjectsCache;
116-
11795 NSString *localId;
11896
11997 // This queue is used to guarantee the order of *Eventually commands
@@ -654,7 +632,6 @@ - (BFTask *)_saveChildrenInBackgroundWithCurrentUser:(PFUser *)currentUser sessi
654632
655633- (BOOL )isDirty : (BOOL )considerChildren {
656634 @synchronized (lock) {
657- [self checkForChangesToMutableContainers ];
658635 if (self._state .deleted || dirty || [self _hasChanges ]) {
659636 return YES ;
660637 }
@@ -681,7 +658,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
681658 [seenObjects addObject: self ];
682659
683660 @synchronized (lock) {
684- [self checkpointAllMutableContainers ];
685661 if (self._state .deleted || dirty || [self _hasChanges ]) {
686662 return YES ;
687663 }
@@ -700,62 +676,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
700676 }
701677}
702678
703- // /--------------------------------------
704- #pragma mark - Mutable container management
705- // /--------------------------------------
706-
707- - (void )checkpointAllMutableContainers {
708- @synchronized (lock) {
709- [_estimatedData enumerateKeysAndObjectsUsingBlock: ^(NSString *key, id obj, BOOL *stop) {
710- [self checkpointMutableContainer: obj];
711- }];
712- }
713- }
714-
715- - (void )checkpointMutableContainer : (id )object {
716- @synchronized (lock) {
717- if (PFObjectValueIsKindOfMutableContainerClass (object)) {
718- [hashedObjectsCache setObject: [PFJSONCacheItem cacheFromObject: object]
719- forKey: [NSValue valueWithNonretainedObject: object]];
720- }
721- }
722- }
723-
724- - (void )checkForChangesToMutableContainer : (id )object forKey : (NSString *)key {
725- @synchronized (lock) {
726- // If this is a mutable container, we should check its contents.
727- if (PFObjectValueIsKindOfMutableContainerClass (object)) {
728- PFJSONCacheItem *oldCacheItem = [hashedObjectsCache objectForKey: [NSValue valueWithNonretainedObject: object]];
729- if (!oldCacheItem) {
730- [NSException raise: NSInternalInconsistencyException
731- format: @" PFObject contains container item that isn't cached." ];
732- } else {
733- PFJSONCacheItem *newCacheItem = [PFJSONCacheItem cacheFromObject: object];
734- if (![oldCacheItem isEqual: newCacheItem]) {
735- // A mutable container changed out from under us. Treat it as a set operation.
736- [self setObject: object forKey: key];
737- }
738- }
739- } else {
740- [hashedObjectsCache removeObjectForKey: [NSValue valueWithNonretainedObject: object]];
741- }
742- }
743- }
744-
745- - (void )checkForChangesToMutableContainers {
746- @synchronized (lock) {
747- NSMutableArray *unexaminedCacheKeys = [[hashedObjectsCache allKeys ] mutableCopy ];
748- NSDictionary *reachableData = _estimatedData.dictionaryRepresentation ;
749- [reachableData enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
750- [unexaminedCacheKeys removeObject: [NSValue valueWithNonretainedObject: obj]];
751- [self checkForChangesToMutableContainer: obj forKey: key];
752- }];
753-
754- // Remove unchecked cache entries.
755- [hashedObjectsCache removeObjectsForKeys: unexaminedCacheKeys];
756- }
757- }
758-
759679// /--------------------------------------
760680#pragma mark - Data Availability
761681// /--------------------------------------
@@ -957,7 +877,6 @@ + (BFTask *)_migrateObjectInBackgroundFromFile:(NSString *)fileName
957877- (NSDictionary *)RESTDictionaryWithObjectEncoder : (PFEncoder *)objectEncoder
958878 operationSetUUIDs : (NSArray **)operationSetUUIDs {
959879 @synchronized (lock) {
960- [self checkForChangesToMutableContainers ];
961880 PFObjectState *state = self._state ;
962881 return [self RESTDictionaryWithObjectEncoder: objectEncoder
963882 operationSetUUIDs: operationSetUUIDs
@@ -1096,15 +1015,11 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
10961015 if ([key isEqualToString: PFObjectACLRESTKey]) {
10971016 PFACL *acl = [PFACL ACLWithDictionary: obj];
10981017 [state setServerDataObject: acl forKey: PFObjectACLRESTKey];
1099- [self checkpointMutableContainer: acl];
11001018 return ;
11011019 }
11021020
11031021 // Should be decoded
11041022 id decodedObject = [decoder decodeObject: obj];
1105- if (PFObjectValueIsKindOfMutableContainerClass (decodedObject)) {
1106- [self checkpointMutableContainer: decodedObject];
1107- }
11081023 [state setServerDataObject: decodedObject forKey: key];
11091024 }];
11101025 if (state.updatedAt == nil && state.createdAt != nil ) {
@@ -1123,7 +1038,6 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
11231038 }
11241039 }
11251040 [self rebuildEstimatedData ];
1126- [self checkpointAllMutableContainers ];
11271041 }
11281042}
11291043
@@ -1223,8 +1137,6 @@ - (BFTask *)_enqueueSaveEventuallyOperationAsync:(PFOperationSet *)operationSet
12231137- (NSMutableDictionary *)_convertToDictionaryForSaving : (PFOperationSet *)changes
12241138 withObjectEncoder : (PFEncoder *)encoder {
12251139 @synchronized (lock) {
1226- [self checkForChangesToMutableContainers ];
1227-
12281140 NSMutableDictionary *serialized = [NSMutableDictionary dictionary ];
12291141 [changes enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
12301142 serialized[key] = obj;
@@ -1239,12 +1151,11 @@ - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
12391151 */
12401152- (void )performOperation : (PFFieldOperation *)operation forKey : (NSString *)key {
12411153 @synchronized (lock) {
1242- id newValue = [_estimatedData applyFieldOperation: operation forKey: key];
1154+ [_estimatedData applyFieldOperation: operation forKey: key];
12431155
12441156 PFFieldOperation *oldOperation = [[self unsavedChanges ] objectForKey: key];
12451157 PFFieldOperation *newOperation = [operation mergeWithPrevious: oldOperation];
12461158 [[self unsavedChanges ] setObject: newOperation forKey: key];
1247- [self checkpointMutableContainer: newValue];
12481159 [_availableKeys addObject: key];
12491160 }
12501161}
@@ -1310,7 +1221,6 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
13101221 state.updatedAt = other.updatedAt ;
13111222 state.serverData = [other._state.serverData mutableCopy ];
13121223 self._state = state;
1313- [self checkpointAllMutableContainers ];
13141224
13151225 dirty = NO ;
13161226
@@ -1321,13 +1231,11 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
13211231
13221232- (void )_mergeAfterFetchWithResult : (NSDictionary *)result decoder : (PFDecoder *)decoder completeData : (BOOL )completeData {
13231233 @synchronized (lock) {
1324- [self checkForChangesToMutableContainers ];
13251234 [self _mergeFromServerWithResult: result decoder: decoder completeData: completeData];
13261235 if (completeData) {
13271236 [self removeOldKeysAfterFetch: result];
13281237 }
13291238 [self rebuildEstimatedData ];
1330- [self checkpointAllMutableContainers ];
13311239 }
13321240}
13331241
@@ -1356,16 +1264,12 @@ - (void)_mergeAfterSaveWithResult:(NSDictionary *)result decoder:(PFDecoder *)de
13561264 PFOperationSet *operationsForNextSave = operationSetQueue[0 ];
13571265 [operationsForNextSave mergeOperationSet: operationsBeforeSave];
13581266 } else {
1359- // Merge the data from the save and the data from the server into serverData.
1360- [self checkForChangesToMutableContainers ];
1361-
13621267 PFMutableObjectState *state = [self ._state mutableCopy ];
13631268 [state applyOperationSet: operationsBeforeSave];
13641269 self._state = state;
13651270
13661271 [self _mergeFromServerWithResult: result decoder: decoder completeData: NO ];
13671272 [self rebuildEstimatedData ];
1368- [self checkpointAllMutableContainers ];
13691273 }
13701274 }
13711275}
@@ -1399,7 +1303,6 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
13991303 } else if ([key isEqualToString: PFObjectACLRESTKey]) {
14001304 PFACL *acl = [PFACL ACLWithDictionary: obj];
14011305 [state setServerDataObject: acl forKey: key];
1402- [self checkpointMutableContainer: acl];
14031306 } else {
14041307 [state setServerDataObject: [decoder decodeObject: obj] forKey: key];
14051308 }
@@ -1689,7 +1592,6 @@ - (instancetype)init {
16891592 _estimatedData = [PFObjectEstimatedData estimatedDataFromServerData: _pfinternal_state.serverData
16901593 operationSetQueue: operationSetQueue];
16911594 _availableKeys = [NSMutableSet set ];
1692- hashedObjectsCache = [[NSMutableDictionary alloc ] init ];
16931595 self.taskQueue = [[PFTaskQueue alloc ] init ];
16941596 _eventuallyTaskQueue = [[PFTaskQueue alloc ] init ];
16951597
@@ -2057,7 +1959,6 @@ - (BOOL)isDirty {
20571959
20581960- (BOOL )isDirtyForKey : (NSString *)key {
20591961 @synchronized (lock) {
2060- [self checkForChangesToMutableContainer: _estimatedData[key] forKey: key];
20611962 return !![[self unsavedChanges ] objectForKey: key];
20621963 }
20631964}
@@ -2302,7 +2203,6 @@ - (void)revert {
23022203 [_availableKeys intersectSet: persistentKeys];
23032204
23042205 [self rebuildEstimatedData ];
2305- [self checkpointAllMutableContainers ];
23062206 }
23072207 }
23082208}
@@ -2313,7 +2213,6 @@ - (void)revertObjectForKey:(NSString *)key {
23132213 [[self unsavedChanges ] removeObjectForKey: key];
23142214 [self rebuildEstimatedData ];
23152215 [_availableKeys removeObject: key];
2316- [self checkpointAllMutableContainers ];
23172216 }
23182217 }
23192218}
0 commit comments