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