@@ -79,25 +79,6 @@ static void PFObjectAssertValueIsKindOfValidClass(id object) {
79
79
PFParameterAssert (NO , @" PFObject values may not have class: %@ " , [object class ]);
80
80
}
81
81
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
-
101
82
@interface PFObject () <PFObjectPrivateSubclass> {
102
83
// A lock for accessing any of the internal state of this object.
103
84
// Guards basically all of the variables below.
@@ -111,9 +92,6 @@ @interface PFObject () <PFObjectPrivateSubclass> {
111
92
// TODO (grantland): Derive this off the EventuallyPins as opposed to +/- count.
112
93
NSUInteger _deletingEventuallyCount;
113
94
114
- // A dictionary that maps id (objects) => PFJSONCache
115
- NSMutableDictionary *hashedObjectsCache;
116
-
117
95
NSString *localId;
118
96
119
97
// This queue is used to guarantee the order of *Eventually commands
@@ -656,7 +634,6 @@ - (BFTask *)_saveChildrenInBackgroundWithCurrentUser:(PFUser *)currentUser sessi
656
634
657
635
- (BOOL )isDirty : (BOOL )considerChildren {
658
636
@synchronized (lock) {
659
- [self checkForChangesToMutableContainers ];
660
637
if (self._state .deleted || dirty || [self _hasChanges ]) {
661
638
return YES ;
662
639
}
@@ -683,7 +660,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
683
660
[seenObjects addObject: self ];
684
661
685
662
@synchronized (lock) {
686
- [self checkpointAllMutableContainers ];
687
663
if (self._state .deleted || dirty || [self _hasChanges ]) {
688
664
return YES ;
689
665
}
@@ -702,62 +678,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
702
678
}
703
679
}
704
680
705
- // /--------------------------------------
706
- #pragma mark - Mutable container management
707
- // /--------------------------------------
708
-
709
- - (void )checkpointAllMutableContainers {
710
- @synchronized (lock) {
711
- [_estimatedData enumerateKeysAndObjectsUsingBlock: ^(NSString *key, id obj, BOOL *stop) {
712
- [self checkpointMutableContainer: obj];
713
- }];
714
- }
715
- }
716
-
717
- - (void )checkpointMutableContainer : (id )object {
718
- @synchronized (lock) {
719
- if (PFObjectValueIsKindOfMutableContainerClass (object)) {
720
- [hashedObjectsCache setObject: [PFJSONCacheItem cacheFromObject: object]
721
- forKey: [NSValue valueWithNonretainedObject: object]];
722
- }
723
- }
724
- }
725
-
726
- - (void )checkForChangesToMutableContainer : (id )object forKey : (NSString *)key {
727
- @synchronized (lock) {
728
- // If this is a mutable container, we should check its contents.
729
- if (PFObjectValueIsKindOfMutableContainerClass (object)) {
730
- PFJSONCacheItem *oldCacheItem = [hashedObjectsCache objectForKey: [NSValue valueWithNonretainedObject: object]];
731
- if (!oldCacheItem) {
732
- [NSException raise :NSInternalInconsistencyException
733
- format: @" PFObject contains container item that isn't cached." ];
734
- } else {
735
- PFJSONCacheItem *newCacheItem = [PFJSONCacheItem cacheFromObject: object];
736
- if (![oldCacheItem isEqual: newCacheItem]) {
737
- // A mutable container changed out from under us. Treat it as a set operation.
738
- [self setObject: object forKey: key];
739
- }
740
- }
741
- } else {
742
- [hashedObjectsCache removeObjectForKey: [NSValue valueWithNonretainedObject: object]];
743
- }
744
- }
745
- }
746
-
747
- - (void )checkForChangesToMutableContainers {
748
- @synchronized (lock) {
749
- NSMutableArray *unexaminedCacheKeys = [[hashedObjectsCache allKeys ] mutableCopy ];
750
- NSDictionary *reachableData = _estimatedData.dictionaryRepresentation ;
751
- [reachableData enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
752
- [unexaminedCacheKeys removeObject: [NSValue valueWithNonretainedObject: obj]];
753
- [self checkForChangesToMutableContainer: obj forKey: key];
754
- }];
755
-
756
- // Remove unchecked cache entries.
757
- [hashedObjectsCache removeObjectsForKeys: unexaminedCacheKeys];
758
- }
759
- }
760
-
761
681
// /--------------------------------------
762
682
#pragma mark - Data Availability
763
683
// /--------------------------------------
@@ -962,7 +882,6 @@ - (NSDictionary *)RESTDictionaryWithObjectEncoder:(PFEncoder *)objectEncoder
962
882
PFObjectState *state = nil ;
963
883
NSUInteger deletingEventuallyCount = 0 ;
964
884
@synchronized (lock) {
965
- [self checkForChangesToMutableContainers ];
966
885
state = self._state ;
967
886
operationQueue = [[NSArray alloc ] initWithArray: operationSetQueue copyItems: YES ];
968
887
deletingEventuallyCount = _deletingEventuallyCount;
@@ -1106,15 +1025,11 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1106
1025
if ([key isEqualToString: PFObjectACLRESTKey]) {
1107
1026
PFACL *acl = [PFACL ACLWithDictionary: obj];
1108
1027
[state setServerDataObject: acl forKey: PFObjectACLRESTKey];
1109
- [self checkpointMutableContainer: acl];
1110
1028
return ;
1111
1029
}
1112
1030
1113
1031
// Should be decoded
1114
1032
id decodedObject = [decoder decodeObject: obj];
1115
- if (PFObjectValueIsKindOfMutableContainerClass (decodedObject)) {
1116
- [self checkpointMutableContainer: decodedObject];
1117
- }
1118
1033
[state setServerDataObject: decodedObject forKey: key];
1119
1034
}];
1120
1035
if (state.updatedAt == nil && state.createdAt != nil ) {
@@ -1133,7 +1048,6 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1133
1048
}
1134
1049
}
1135
1050
[self rebuildEstimatedData ];
1136
- [self checkpointAllMutableContainers ];
1137
1051
}
1138
1052
}
1139
1053
@@ -1233,8 +1147,6 @@ - (BFTask *)_enqueueSaveEventuallyOperationAsync:(PFOperationSet *)operationSet
1233
1147
- (NSMutableDictionary *)_convertToDictionaryForSaving : (PFOperationSet *)changes
1234
1148
withObjectEncoder : (PFEncoder *)encoder {
1235
1149
@synchronized (lock) {
1236
- [self checkForChangesToMutableContainers ];
1237
-
1238
1150
NSMutableDictionary *serialized = [NSMutableDictionary dictionary ];
1239
1151
[changes enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
1240
1152
serialized[key] = obj;
@@ -1249,12 +1161,11 @@ - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
1249
1161
*/
1250
1162
- (void )performOperation : (PFFieldOperation *)operation forKey : (NSString *)key {
1251
1163
@synchronized (lock) {
1252
- id newValue = [_estimatedData applyFieldOperation: operation forKey: key];
1164
+ [_estimatedData applyFieldOperation: operation forKey: key];
1253
1165
1254
1166
PFFieldOperation *oldOperation = [[self unsavedChanges ] objectForKey: key];
1255
1167
PFFieldOperation *newOperation = [operation mergeWithPrevious: oldOperation];
1256
1168
[[self unsavedChanges ] setObject: newOperation forKey: key];
1257
- [self checkpointMutableContainer: newValue];
1258
1169
[_availableKeys addObject: key];
1259
1170
}
1260
1171
}
@@ -1320,7 +1231,6 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1320
1231
state.updatedAt = other.updatedAt ;
1321
1232
state.serverData = [other._state.serverData mutableCopy ];
1322
1233
self._state = state;
1323
- [self checkpointAllMutableContainers ];
1324
1234
1325
1235
dirty = NO ;
1326
1236
@@ -1331,13 +1241,11 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1331
1241
1332
1242
- (void )_mergeAfterFetchWithResult : (NSDictionary *)result decoder : (PFDecoder *)decoder completeData : (BOOL )completeData {
1333
1243
@synchronized (lock) {
1334
- [self checkForChangesToMutableContainers ];
1335
1244
[self _mergeFromServerWithResult: result decoder: decoder completeData: completeData];
1336
1245
if (completeData) {
1337
1246
[self removeOldKeysAfterFetch: result];
1338
1247
}
1339
1248
[self rebuildEstimatedData ];
1340
- [self checkpointAllMutableContainers ];
1341
1249
}
1342
1250
}
1343
1251
@@ -1366,16 +1274,12 @@ - (void)_mergeAfterSaveWithResult:(NSDictionary *)result decoder:(PFDecoder *)de
1366
1274
PFOperationSet *operationsForNextSave = operationSetQueue[0 ];
1367
1275
[operationsForNextSave mergeOperationSet: operationsBeforeSave];
1368
1276
} else {
1369
- // Merge the data from the save and the data from the server into serverData.
1370
- [self checkForChangesToMutableContainers ];
1371
-
1372
1277
PFMutableObjectState *state = [self ._state mutableCopy ];
1373
1278
[state applyOperationSet: operationsBeforeSave];
1374
1279
self._state = state;
1375
1280
1376
1281
[self _mergeFromServerWithResult: result decoder: decoder completeData: NO ];
1377
1282
[self rebuildEstimatedData ];
1378
- [self checkpointAllMutableContainers ];
1379
1283
}
1380
1284
}
1381
1285
}
@@ -1409,7 +1313,6 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
1409
1313
} else if ([key isEqualToString: PFObjectACLRESTKey]) {
1410
1314
PFACL *acl = [PFACL ACLWithDictionary: obj];
1411
1315
[state setServerDataObject: acl forKey: key];
1412
- [self checkpointMutableContainer: acl];
1413
1316
} else {
1414
1317
[state setServerDataObject: [decoder decodeObject: obj] forKey: key];
1415
1318
}
@@ -1699,7 +1602,6 @@ - (instancetype)init {
1699
1602
_estimatedData = [PFObjectEstimatedData estimatedDataFromServerData: _pfinternal_state.serverData
1700
1603
operationSetQueue: operationSetQueue];
1701
1604
_availableKeys = [NSMutableSet set ];
1702
- hashedObjectsCache = [[NSMutableDictionary alloc ] init ];
1703
1605
self.taskQueue = [[PFTaskQueue alloc ] init ];
1704
1606
_eventuallyTaskQueue = [[PFTaskQueue alloc ] init ];
1705
1607
@@ -2067,7 +1969,6 @@ - (BOOL)isDirty {
2067
1969
2068
1970
- (BOOL )isDirtyForKey : (NSString *)key {
2069
1971
@synchronized (lock) {
2070
- [self checkForChangesToMutableContainer: _estimatedData[key] forKey: key];
2071
1972
return !![[self unsavedChanges ] objectForKey: key];
2072
1973
}
2073
1974
}
@@ -2312,7 +2213,6 @@ - (void)revert {
2312
2213
[_availableKeys intersectSet: persistentKeys];
2313
2214
2314
2215
[self rebuildEstimatedData ];
2315
- [self checkpointAllMutableContainers ];
2316
2216
}
2317
2217
}
2318
2218
}
@@ -2323,7 +2223,6 @@ - (void)revertObjectForKey:(NSString *)key {
2323
2223
[[self unsavedChanges ] removeObjectForKey: key];
2324
2224
[self rebuildEstimatedData ];
2325
2225
[_availableKeys removeObject: key];
2326
- [self checkpointAllMutableContainers ];
2327
2226
}
2328
2227
}
2329
2228
}
0 commit comments