@@ -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
@@ -653,7 +631,6 @@ - (BFTask *)_saveChildrenInBackgroundWithCurrentUser:(PFUser *)currentUser sessi
653
631
654
632
- (BOOL )isDirty : (BOOL )considerChildren {
655
633
@synchronized (lock) {
656
- [self checkForChangesToMutableContainers ];
657
634
if (self._state .deleted || dirty || [self _hasChanges ]) {
658
635
return YES ;
659
636
}
@@ -680,62 +657,6 @@ - (void)_setDirty:(BOOL)aDirty {
680
657
}
681
658
}
682
659
683
- // /--------------------------------------
684
- #pragma mark - Mutable container management
685
- // /--------------------------------------
686
-
687
- - (void )checkpointAllMutableContainers {
688
- @synchronized (lock) {
689
- [_estimatedData enumerateKeysAndObjectsUsingBlock: ^(NSString *key, id obj, BOOL *stop) {
690
- [self checkpointMutableContainer: obj];
691
- }];
692
- }
693
- }
694
-
695
- - (void )checkpointMutableContainer : (id )object {
696
- @synchronized (lock) {
697
- if (PFObjectValueIsKindOfMutableContainerClass (object)) {
698
- [hashedObjectsCache setObject: [PFJSONCacheItem cacheFromObject: object]
699
- forKey: [NSValue valueWithNonretainedObject: object]];
700
- }
701
- }
702
- }
703
-
704
- - (void )checkForChangesToMutableContainer : (id )object forKey : (NSString *)key {
705
- @synchronized (lock) {
706
- // If this is a mutable container, we should check its contents.
707
- if (PFObjectValueIsKindOfMutableContainerClass (object)) {
708
- PFJSONCacheItem *oldCacheItem = [hashedObjectsCache objectForKey: [NSValue valueWithNonretainedObject: object]];
709
- if (!oldCacheItem) {
710
- [NSException raise: NSInternalInconsistencyException
711
- format: @" PFObject contains container item that isn't cached." ];
712
- } else {
713
- PFJSONCacheItem *newCacheItem = [PFJSONCacheItem cacheFromObject: object];
714
- if (![oldCacheItem isEqual: newCacheItem]) {
715
- // A mutable container changed out from under us. Treat it as a set operation.
716
- [self setObject: object forKey: key];
717
- }
718
- }
719
- } else {
720
- [hashedObjectsCache removeObjectForKey: [NSValue valueWithNonretainedObject: object]];
721
- }
722
- }
723
- }
724
-
725
- - (void )checkForChangesToMutableContainers {
726
- @synchronized (lock) {
727
- NSMutableArray *unexaminedCacheKeys = [[hashedObjectsCache allKeys ] mutableCopy ];
728
- NSDictionary *reachableData = _estimatedData.dictionaryRepresentation ;
729
- [reachableData enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
730
- [unexaminedCacheKeys removeObject: [NSValue valueWithNonretainedObject: obj]];
731
- [self checkForChangesToMutableContainer: obj forKey: key];
732
- }];
733
-
734
- // Remove unchecked cache entries.
735
- [hashedObjectsCache removeObjectsForKeys: unexaminedCacheKeys];
736
- }
737
- }
738
-
739
660
// /--------------------------------------
740
661
#pragma mark - Data Availability
741
662
// /--------------------------------------
@@ -942,7 +863,6 @@ + (BFTask *)_migrateObjectInBackgroundFromFile:(NSString *)fileName
942
863
- (NSDictionary *)RESTDictionaryWithObjectEncoder : (PFEncoder *)objectEncoder
943
864
operationSetUUIDs : (NSArray **)operationSetUUIDs {
944
865
@synchronized (lock) {
945
- [self checkForChangesToMutableContainers ];
946
866
PFObjectState *state = self._state ;
947
867
return [self RESTDictionaryWithObjectEncoder: objectEncoder
948
868
operationSetUUIDs: operationSetUUIDs
@@ -1081,15 +1001,11 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1081
1001
if ([key isEqualToString: PFObjectACLRESTKey]) {
1082
1002
PFACL *acl = [PFACL ACLWithDictionary: obj];
1083
1003
[state setServerDataObject: acl forKey: PFObjectACLRESTKey];
1084
- [self checkpointMutableContainer: acl];
1085
1004
return ;
1086
1005
}
1087
1006
1088
1007
// Should be decoded
1089
1008
id decodedObject = [decoder decodeObject: obj];
1090
- if (PFObjectValueIsKindOfMutableContainerClass (decodedObject)) {
1091
- [self checkpointMutableContainer: decodedObject];
1092
- }
1093
1009
[state setServerDataObject: decodedObject forKey: key];
1094
1010
}];
1095
1011
if (state.updatedAt == nil && state.createdAt != nil ) {
@@ -1108,7 +1024,6 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
1108
1024
}
1109
1025
}
1110
1026
[self rebuildEstimatedData ];
1111
- [self checkpointAllMutableContainers ];
1112
1027
}
1113
1028
}
1114
1029
@@ -1207,8 +1122,6 @@ - (BFTask *)_enqueueSaveEventuallyOperationAsync:(PFOperationSet *)operationSet
1207
1122
- (NSMutableDictionary *)_convertToDictionaryForSaving : (PFOperationSet *)changes
1208
1123
withObjectEncoder : (PFEncoder *)encoder {
1209
1124
@synchronized (lock) {
1210
- [self checkForChangesToMutableContainers ];
1211
-
1212
1125
NSMutableDictionary *serialized = [NSMutableDictionary dictionary ];
1213
1126
[changes enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
1214
1127
serialized[key] = obj;
@@ -1223,12 +1136,11 @@ - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
1223
1136
*/
1224
1137
- (void )performOperation : (PFFieldOperation *)operation forKey : (NSString *)key {
1225
1138
@synchronized (lock) {
1226
- id newValue = [_estimatedData applyFieldOperation: operation forKey: key];
1139
+ [_estimatedData applyFieldOperation: operation forKey: key];
1227
1140
1228
1141
PFFieldOperation *oldOperation = [[self unsavedChanges ] objectForKey: key];
1229
1142
PFFieldOperation *newOperation = [operation mergeWithPrevious: oldOperation];
1230
1143
[[self unsavedChanges ] setObject: newOperation forKey: key];
1231
- [self checkpointMutableContainer: newValue];
1232
1144
[_availableKeys addObject: key];
1233
1145
}
1234
1146
}
@@ -1294,7 +1206,6 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1294
1206
state.updatedAt = other.updatedAt ;
1295
1207
state.serverData = [other._state.serverData mutableCopy ];
1296
1208
self._state = state;
1297
- [self checkpointAllMutableContainers ];
1298
1209
1299
1210
dirty = NO ;
1300
1211
@@ -1305,13 +1216,11 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
1305
1216
1306
1217
- (void )_mergeAfterFetchWithResult : (NSDictionary *)result decoder : (PFDecoder *)decoder completeData : (BOOL )completeData {
1307
1218
@synchronized (lock) {
1308
- [self checkForChangesToMutableContainers ];
1309
1219
[self _mergeFromServerWithResult: result decoder: decoder completeData: completeData];
1310
1220
if (completeData) {
1311
1221
[self removeOldKeysAfterFetch: result];
1312
1222
}
1313
1223
[self rebuildEstimatedData ];
1314
- [self checkpointAllMutableContainers ];
1315
1224
}
1316
1225
}
1317
1226
@@ -1340,16 +1249,12 @@ - (void)_mergeAfterSaveWithResult:(NSDictionary *)result decoder:(PFDecoder *)de
1340
1249
PFOperationSet *operationsForNextSave = operationSetQueue[0 ];
1341
1250
[operationsForNextSave mergeOperationSet: operationsBeforeSave];
1342
1251
} else {
1343
- // Merge the data from the save and the data from the server into serverData.
1344
- [self checkForChangesToMutableContainers ];
1345
-
1346
1252
PFMutableObjectState *state = [self ._state mutableCopy ];
1347
1253
[state applyOperationSet: operationsBeforeSave];
1348
1254
self._state = state;
1349
1255
1350
1256
[self _mergeFromServerWithResult: result decoder: decoder completeData: NO ];
1351
1257
[self rebuildEstimatedData ];
1352
- [self checkpointAllMutableContainers ];
1353
1258
}
1354
1259
}
1355
1260
}
@@ -1371,7 +1276,6 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
1371
1276
} else if ([key isEqualToString: PFObjectACLRESTKey]) {
1372
1277
PFACL *acl = [PFACL ACLWithDictionary: obj];
1373
1278
[state setServerDataObject: acl forKey: key];
1374
- [self checkpointMutableContainer: acl];
1375
1279
} else {
1376
1280
[state setServerDataObject: [decoder decodeObject: obj] forKey: key];
1377
1281
}
@@ -1665,7 +1569,6 @@ - (instancetype)init {
1665
1569
_estimatedData = [PFObjectEstimatedData estimatedDataFromServerData: _pfinternal_state.serverData
1666
1570
operationSetQueue: operationSetQueue];
1667
1571
_availableKeys = [NSMutableSet set ];
1668
- hashedObjectsCache = [[NSMutableDictionary alloc ] init ];
1669
1572
self.taskQueue = [[PFTaskQueue alloc ] init ];
1670
1573
_eventuallyTaskQueue = [[PFTaskQueue alloc ] init ];
1671
1574
@@ -2011,7 +1914,6 @@ - (BOOL)isDirty {
2011
1914
2012
1915
- (BOOL )isDirtyForKey : (NSString *)key {
2013
1916
@synchronized (lock) {
2014
- [self checkForChangesToMutableContainer: _estimatedData[key] forKey: key];
2015
1917
return !![[self unsavedChanges ] objectForKey: key];
2016
1918
}
2017
1919
}
@@ -2256,7 +2158,6 @@ - (void)revert {
2256
2158
[_availableKeys intersectSet: persistentKeys];
2257
2159
2258
2160
[self rebuildEstimatedData ];
2259
- [self checkpointAllMutableContainers ];
2260
2161
}
2261
2162
}
2262
2163
}
@@ -2267,7 +2168,6 @@ - (void)revertObjectForKey:(NSString *)key {
2267
2168
[[self unsavedChanges ] removeObjectForKey: key];
2268
2169
[self rebuildEstimatedData ];
2269
2170
[_availableKeys removeObject: key];
2270
- [self checkpointAllMutableContainers ];
2271
2171
}
2272
2172
}
2273
2173
}
0 commit comments