@@ -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
@@ -654,7 +632,6 @@ - (BFTask *)_saveChildrenInBackgroundWithCurrentUser:(PFUser *)currentUser sessi
654
632
655
633
- (BOOL )isDirty : (BOOL )considerChildren {
656
634
@synchronized (lock) {
657
- [self checkForChangesToMutableContainers ];
658
635
if (self._state .deleted || dirty || [self _hasChanges ]) {
659
636
return YES ;
660
637
}
@@ -681,7 +658,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
681
658
[seenObjects addObject: self ];
682
659
683
660
@synchronized (lock) {
684
- [self checkpointAllMutableContainers ];
685
661
if (self._state .deleted || dirty || [self _hasChanges ]) {
686
662
return YES ;
687
663
}
@@ -700,62 +676,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
700
676
}
701
677
}
702
678
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
-
759
679
// /--------------------------------------
760
680
#pragma mark - Data Availability
761
681
// /--------------------------------------
@@ -957,7 +877,6 @@ + (BFTask *)_migrateObjectInBackgroundFromFile:(NSString *)fileName
957
877
- (NSDictionary *)RESTDictionaryWithObjectEncoder : (PFEncoder *)objectEncoder
958
878
operationSetUUIDs : (NSArray **)operationSetUUIDs {
959
879
@synchronized (lock) {
960
- [self checkForChangesToMutableContainers ];
961
880
PFObjectState *state = self._state ;
962
881
return [self RESTDictionaryWithObjectEncoder: objectEncoder
963
882
operationSetUUIDs: operationSetUUIDs
@@ -1096,15 +1015,11 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1096
1015
if ([key isEqualToString: PFObjectACLRESTKey]) {
1097
1016
PFACL *acl = [PFACL ACLWithDictionary: obj];
1098
1017
[state setServerDataObject: acl forKey: PFObjectACLRESTKey];
1099
- [self checkpointMutableContainer: acl];
1100
1018
return ;
1101
1019
}
1102
1020
1103
1021
// Should be decoded
1104
1022
id decodedObject = [decoder decodeObject: obj];
1105
- if (PFObjectValueIsKindOfMutableContainerClass (decodedObject)) {
1106
- [self checkpointMutableContainer: decodedObject];
1107
- }
1108
1023
[state setServerDataObject: decodedObject forKey: key];
1109
1024
}];
1110
1025
if (state.updatedAt == nil && state.createdAt != nil ) {
@@ -1123,7 +1038,6 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1123
1038
}
1124
1039
}
1125
1040
[self rebuildEstimatedData ];
1126
- [self checkpointAllMutableContainers ];
1127
1041
}
1128
1042
}
1129
1043
@@ -1223,8 +1137,6 @@ - (BFTask *)_enqueueSaveEventuallyOperationAsync:(PFOperationSet *)operationSet
1223
1137
- (NSMutableDictionary *)_convertToDictionaryForSaving : (PFOperationSet *)changes
1224
1138
withObjectEncoder : (PFEncoder *)encoder {
1225
1139
@synchronized (lock) {
1226
- [self checkForChangesToMutableContainers ];
1227
-
1228
1140
NSMutableDictionary *serialized = [NSMutableDictionary dictionary ];
1229
1141
[changes enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
1230
1142
serialized[key] = obj;
@@ -1239,12 +1151,11 @@ - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
1239
1151
*/
1240
1152
- (void )performOperation : (PFFieldOperation *)operation forKey : (NSString *)key {
1241
1153
@synchronized (lock) {
1242
- id newValue = [_estimatedData applyFieldOperation: operation forKey: key];
1154
+ [_estimatedData applyFieldOperation: operation forKey: key];
1243
1155
1244
1156
PFFieldOperation *oldOperation = [[self unsavedChanges ] objectForKey: key];
1245
1157
PFFieldOperation *newOperation = [operation mergeWithPrevious: oldOperation];
1246
1158
[[self unsavedChanges ] setObject: newOperation forKey: key];
1247
- [self checkpointMutableContainer: newValue];
1248
1159
[_availableKeys addObject: key];
1249
1160
}
1250
1161
}
@@ -1310,7 +1221,6 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1310
1221
state.updatedAt = other.updatedAt ;
1311
1222
state.serverData = [other._state.serverData mutableCopy ];
1312
1223
self._state = state;
1313
- [self checkpointAllMutableContainers ];
1314
1224
1315
1225
dirty = NO ;
1316
1226
@@ -1321,13 +1231,11 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1321
1231
1322
1232
- (void )_mergeAfterFetchWithResult : (NSDictionary *)result decoder : (PFDecoder *)decoder completeData : (BOOL )completeData {
1323
1233
@synchronized (lock) {
1324
- [self checkForChangesToMutableContainers ];
1325
1234
[self _mergeFromServerWithResult: result decoder: decoder completeData: completeData];
1326
1235
if (completeData) {
1327
1236
[self removeOldKeysAfterFetch: result];
1328
1237
}
1329
1238
[self rebuildEstimatedData ];
1330
- [self checkpointAllMutableContainers ];
1331
1239
}
1332
1240
}
1333
1241
@@ -1356,16 +1264,12 @@ - (void)_mergeAfterSaveWithResult:(NSDictionary *)result decoder:(PFDecoder *)de
1356
1264
PFOperationSet *operationsForNextSave = operationSetQueue[0 ];
1357
1265
[operationsForNextSave mergeOperationSet: operationsBeforeSave];
1358
1266
} else {
1359
- // Merge the data from the save and the data from the server into serverData.
1360
- [self checkForChangesToMutableContainers ];
1361
-
1362
1267
PFMutableObjectState *state = [self ._state mutableCopy ];
1363
1268
[state applyOperationSet: operationsBeforeSave];
1364
1269
self._state = state;
1365
1270
1366
1271
[self _mergeFromServerWithResult: result decoder: decoder completeData: NO ];
1367
1272
[self rebuildEstimatedData ];
1368
- [self checkpointAllMutableContainers ];
1369
1273
}
1370
1274
}
1371
1275
}
@@ -1399,7 +1303,6 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
1399
1303
} else if ([key isEqualToString: PFObjectACLRESTKey]) {
1400
1304
PFACL *acl = [PFACL ACLWithDictionary: obj];
1401
1305
[state setServerDataObject: acl forKey: key];
1402
- [self checkpointMutableContainer: acl];
1403
1306
} else {
1404
1307
[state setServerDataObject: [decoder decodeObject: obj] forKey: key];
1405
1308
}
@@ -1689,7 +1592,6 @@ - (instancetype)init {
1689
1592
_estimatedData = [PFObjectEstimatedData estimatedDataFromServerData: _pfinternal_state.serverData
1690
1593
operationSetQueue: operationSetQueue];
1691
1594
_availableKeys = [NSMutableSet set ];
1692
- hashedObjectsCache = [[NSMutableDictionary alloc ] init ];
1693
1595
self.taskQueue = [[PFTaskQueue alloc ] init ];
1694
1596
_eventuallyTaskQueue = [[PFTaskQueue alloc ] init ];
1695
1597
@@ -2057,7 +1959,6 @@ - (BOOL)isDirty {
2057
1959
2058
1960
- (BOOL )isDirtyForKey : (NSString *)key {
2059
1961
@synchronized (lock) {
2060
- [self checkForChangesToMutableContainer: _estimatedData[key] forKey: key];
2061
1962
return !![[self unsavedChanges ] objectForKey: key];
2062
1963
}
2063
1964
}
@@ -2302,7 +2203,6 @@ - (void)revert {
2302
2203
[_availableKeys intersectSet: persistentKeys];
2303
2204
2304
2205
[self rebuildEstimatedData ];
2305
- [self checkpointAllMutableContainers ];
2306
2206
}
2307
2207
}
2308
2208
}
@@ -2313,7 +2213,6 @@ - (void)revertObjectForKey:(NSString *)key {
2313
2213
[[self unsavedChanges ] removeObjectForKey: key];
2314
2214
[self rebuildEstimatedData ];
2315
2215
[_availableKeys removeObject: key];
2316
- [self checkpointAllMutableContainers ];
2317
2216
}
2318
2217
}
2319
2218
}
0 commit comments