@@ -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
int _deletingEventually;
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
// /--------------------------------------
@@ -959,7 +879,6 @@ + (BFTask *)_migrateObjectInBackgroundFromFile:(NSString *)fileName
959
879
- (NSDictionary *)RESTDictionaryWithObjectEncoder : (PFEncoder *)objectEncoder
960
880
operationSetUUIDs : (NSArray **)operationSetUUIDs {
961
881
@synchronized (lock) {
962
- [self checkForChangesToMutableContainers ];
963
882
PFObjectState *state = self._state ;
964
883
return [self RESTDictionaryWithObjectEncoder: objectEncoder
965
884
operationSetUUIDs: operationSetUUIDs
@@ -1098,15 +1017,11 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1098
1017
if ([key isEqualToString: PFObjectACLRESTKey]) {
1099
1018
PFACL *acl = [PFACL ACLWithDictionary: obj];
1100
1019
[state setServerDataObject: acl forKey: PFObjectACLRESTKey];
1101
- [self checkpointMutableContainer: acl];
1102
1020
return ;
1103
1021
}
1104
1022
1105
1023
// Should be decoded
1106
1024
id decodedObject = [decoder decodeObject: obj];
1107
- if (PFObjectValueIsKindOfMutableContainerClass (decodedObject)) {
1108
- [self checkpointMutableContainer: decodedObject];
1109
- }
1110
1025
[state setServerDataObject: decodedObject forKey: key];
1111
1026
}];
1112
1027
if (state.updatedAt == nil && state.createdAt != nil ) {
@@ -1125,7 +1040,6 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1125
1040
}
1126
1041
}
1127
1042
[self rebuildEstimatedData ];
1128
- [self checkpointAllMutableContainers ];
1129
1043
}
1130
1044
}
1131
1045
@@ -1225,8 +1139,6 @@ - (BFTask *)_enqueueSaveEventuallyOperationAsync:(PFOperationSet *)operationSet
1225
1139
- (NSMutableDictionary *)_convertToDictionaryForSaving : (PFOperationSet *)changes
1226
1140
withObjectEncoder : (PFEncoder *)encoder {
1227
1141
@synchronized (lock) {
1228
- [self checkForChangesToMutableContainers ];
1229
-
1230
1142
NSMutableDictionary *serialized = [NSMutableDictionary dictionary ];
1231
1143
[changes enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
1232
1144
serialized[key] = obj;
@@ -1241,12 +1153,11 @@ - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
1241
1153
*/
1242
1154
- (void )performOperation : (PFFieldOperation *)operation forKey : (NSString *)key {
1243
1155
@synchronized (lock) {
1244
- id newValue = [_estimatedData applyFieldOperation: operation forKey: key];
1156
+ [_estimatedData applyFieldOperation: operation forKey: key];
1245
1157
1246
1158
PFFieldOperation *oldOperation = [[self unsavedChanges ] objectForKey: key];
1247
1159
PFFieldOperation *newOperation = [operation mergeWithPrevious: oldOperation];
1248
1160
[[self unsavedChanges ] setObject: newOperation forKey: key];
1249
- [self checkpointMutableContainer: newValue];
1250
1161
[_availableKeys addObject: key];
1251
1162
}
1252
1163
}
@@ -1312,7 +1223,6 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1312
1223
state.updatedAt = other.updatedAt ;
1313
1224
state.serverData = [other._state.serverData mutableCopy ];
1314
1225
self._state = state;
1315
- [self checkpointAllMutableContainers ];
1316
1226
1317
1227
dirty = NO ;
1318
1228
@@ -1323,13 +1233,11 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1323
1233
1324
1234
- (void )_mergeAfterFetchWithResult : (NSDictionary *)result decoder : (PFDecoder *)decoder completeData : (BOOL )completeData {
1325
1235
@synchronized (lock) {
1326
- [self checkForChangesToMutableContainers ];
1327
1236
[self _mergeFromServerWithResult: result decoder: decoder completeData: completeData];
1328
1237
if (completeData) {
1329
1238
[self removeOldKeysAfterFetch: result];
1330
1239
}
1331
1240
[self rebuildEstimatedData ];
1332
- [self checkpointAllMutableContainers ];
1333
1241
}
1334
1242
}
1335
1243
@@ -1358,16 +1266,12 @@ - (void)_mergeAfterSaveWithResult:(NSDictionary *)result decoder:(PFDecoder *)de
1358
1266
PFOperationSet *operationsForNextSave = operationSetQueue[0 ];
1359
1267
[operationsForNextSave mergeOperationSet: operationsBeforeSave];
1360
1268
} else {
1361
- // Merge the data from the save and the data from the server into serverData.
1362
- [self checkForChangesToMutableContainers ];
1363
-
1364
1269
PFMutableObjectState *state = [self ._state mutableCopy ];
1365
1270
[state applyOperationSet: operationsBeforeSave];
1366
1271
self._state = state;
1367
1272
1368
1273
[self _mergeFromServerWithResult: result decoder: decoder completeData: NO ];
1369
1274
[self rebuildEstimatedData ];
1370
- [self checkpointAllMutableContainers ];
1371
1275
}
1372
1276
}
1373
1277
}
@@ -1401,7 +1305,6 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
1401
1305
} else if ([key isEqualToString: PFObjectACLRESTKey]) {
1402
1306
PFACL *acl = [PFACL ACLWithDictionary: obj];
1403
1307
[state setServerDataObject: acl forKey: key];
1404
- [self checkpointMutableContainer: acl];
1405
1308
} else {
1406
1309
[state setServerDataObject: [decoder decodeObject: obj] forKey: key];
1407
1310
}
@@ -1691,7 +1594,6 @@ - (instancetype)init {
1691
1594
_estimatedData = [PFObjectEstimatedData estimatedDataFromServerData: _pfinternal_state.serverData
1692
1595
operationSetQueue: operationSetQueue];
1693
1596
_availableKeys = [NSMutableSet set ];
1694
- hashedObjectsCache = [[NSMutableDictionary alloc ] init ];
1695
1597
self.taskQueue = [[PFTaskQueue alloc ] init ];
1696
1598
_eventuallyTaskQueue = [[PFTaskQueue alloc ] init ];
1697
1599
@@ -2059,7 +1961,6 @@ - (BOOL)isDirty {
2059
1961
2060
1962
- (BOOL )isDirtyForKey : (NSString *)key {
2061
1963
@synchronized (lock) {
2062
- [self checkForChangesToMutableContainer: _estimatedData[key] forKey: key];
2063
1964
return !![[self unsavedChanges ] objectForKey: key];
2064
1965
}
2065
1966
}
@@ -2304,7 +2205,6 @@ - (void)revert {
2304
2205
[_availableKeys intersectSet: persistentKeys];
2305
2206
2306
2207
[self rebuildEstimatedData ];
2307
- [self checkpointAllMutableContainers ];
2308
2208
}
2309
2209
}
2310
2210
}
@@ -2315,7 +2215,6 @@ - (void)revertObjectForKey:(NSString *)key {
2315
2215
[[self unsavedChanges ] removeObjectForKey: key];
2316
2216
[self rebuildEstimatedData ];
2317
2217
[_availableKeys removeObject: key];
2318
- [self checkpointAllMutableContainers ];
2319
2218
}
2320
2219
}
2321
2220
}
0 commit comments