Skip to content

Commit 7123ff2

Browse files
committed
Merge pull request #102 from ParsePlatform/nlutsenko.containers
Removed 'mutable containers' functionality.
2 parents bd0fa4b + f736c17 commit 7123ff2

File tree

5 files changed

+1
-143
lines changed

5 files changed

+1
-143
lines changed

Parse/Internal/Object/PFObjectPrivate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@
229229
///--------------------------------------
230230
#pragma mark - Data helpers
231231
///--------------------------------------
232-
- (void)checkForChangesToMutableContainers;
233232
- (void)rebuildEstimatedData;
234233

235234
///--------------------------------------

Parse/Internal/PFInternalUtils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,5 @@
6464
+ (NSArray *)arrayBySplittingArray:(NSArray *)array withMaximumComponentsPerSegment:(NSUInteger)components;
6565

6666
+ (id)_stringWithFormat:(NSString *)format arguments:(NSArray *)arguments;
67-
@end
68-
69-
@interface PFJSONCacheItem : NSObject
70-
71-
@property (nonatomic, copy, readonly) NSString *hashValue;
72-
73-
- (instancetype)initWithObject:(id)object;
74-
+ (PFJSONCacheItem *)cacheFromObject:(id)object;
7567

7668
@end

Parse/Internal/PFInternalUtils.m

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -269,32 +269,3 @@ + (id)_stringWithFormat:(NSString *)format arguments:(NSArray *)arguments {
269269
}
270270

271271
@end
272-
273-
// A PFJSONCacheItem is a pairing of a json string with its hash value.
274-
// This is used by our mutable container checking.
275-
@implementation PFJSONCacheItem
276-
277-
- (instancetype)initWithObject:(id)object {
278-
self = [super init];
279-
if (!self) return nil;
280-
281-
NSObject *encoded = [[PFPointerOrLocalIdObjectEncoder objectEncoder] encodeObject:object];
282-
NSData *jsonData = [PFJSONSerialization dataFromJSONObject:encoded];
283-
_hashValue = PFMD5HashFromData(jsonData);
284-
285-
return self;
286-
}
287-
288-
- (BOOL)isEqual:(id)otherCache {
289-
if (![otherCache isKindOfClass:[PFJSONCacheItem class]]) {
290-
return NO;
291-
}
292-
293-
return [self.hashValue isEqualToString:[otherCache hashValue]];
294-
}
295-
296-
+ (PFJSONCacheItem *)cacheFromObject:(id)object {
297-
return [[PFJSONCacheItem alloc] initWithObject:object];
298-
}
299-
300-
@end

Parse/PFObject.m

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,6 @@ static void PFObjectAssertValueIsKindOfValidClass(id object) {
7979
PFParameterAssert(NO, @"PFObject values may not have class: %@", [object class]);
8080
}
8181

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-
10182
@interface PFObject () <PFObjectPrivateSubclass> {
10283
// A lock for accessing any of the internal state of this object.
10384
// Guards basically all of the variables below.
@@ -111,9 +92,6 @@ @interface PFObject () <PFObjectPrivateSubclass> {
11192
// TODO (grantland): Derive this off the EventuallyPins as opposed to +/- count.
11293
NSUInteger _deletingEventuallyCount;
11394

114-
// A dictionary that maps id (objects) => PFJSONCache
115-
NSMutableDictionary *hashedObjectsCache;
116-
11795
NSString *localId;
11896

11997
// This queue is used to guarantee the order of *Eventually commands
@@ -656,7 +634,6 @@ - (BFTask *)_saveChildrenInBackgroundWithCurrentUser:(PFUser *)currentUser sessi
656634

657635
- (BOOL)isDirty:(BOOL)considerChildren {
658636
@synchronized (lock) {
659-
[self checkForChangesToMutableContainers];
660637
if (self._state.deleted || dirty || [self _hasChanges]) {
661638
return YES;
662639
}
@@ -683,7 +660,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
683660
[seenObjects addObject:self];
684661

685662
@synchronized(lock) {
686-
[self checkpointAllMutableContainers];
687663
if (self._state.deleted || dirty || [self _hasChanges]) {
688664
return YES;
689665
}
@@ -702,62 +678,6 @@ - (BOOL)_areChildrenDirty:(NSMutableSet *)seenObjects {
702678
}
703679
}
704680

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-
761681
///--------------------------------------
762682
#pragma mark - Data Availability
763683
///--------------------------------------
@@ -962,7 +882,6 @@ - (NSDictionary *)RESTDictionaryWithObjectEncoder:(PFEncoder *)objectEncoder
962882
PFObjectState *state = nil;
963883
NSUInteger deletingEventuallyCount = 0;
964884
@synchronized (lock) {
965-
[self checkForChangesToMutableContainers];
966885
state = self._state;
967886
operationQueue = [[NSArray alloc] initWithArray:operationSetQueue copyItems:YES];
968887
deletingEventuallyCount = _deletingEventuallyCount;
@@ -1106,15 +1025,11 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
11061025
if ([key isEqualToString:PFObjectACLRESTKey]) {
11071026
PFACL *acl = [PFACL ACLWithDictionary:obj];
11081027
[state setServerDataObject:acl forKey:PFObjectACLRESTKey];
1109-
[self checkpointMutableContainer:acl];
11101028
return;
11111029
}
11121030

11131031
// Should be decoded
11141032
id decodedObject = [decoder decodeObject:obj];
1115-
if (PFObjectValueIsKindOfMutableContainerClass(decodedObject)) {
1116-
[self checkpointMutableContainer:decodedObject];
1117-
}
11181033
[state setServerDataObject:decodedObject forKey:key];
11191034
}];
11201035
if (state.updatedAt == nil && state.createdAt != nil) {
@@ -1133,7 +1048,6 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
11331048
}
11341049
}
11351050
[self rebuildEstimatedData];
1136-
[self checkpointAllMutableContainers];
11371051
}
11381052
}
11391053

@@ -1233,8 +1147,6 @@ - (BFTask *)_enqueueSaveEventuallyOperationAsync:(PFOperationSet *)operationSet
12331147
- (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
12341148
withObjectEncoder:(PFEncoder *)encoder {
12351149
@synchronized (lock) {
1236-
[self checkForChangesToMutableContainers];
1237-
12381150
NSMutableDictionary *serialized = [NSMutableDictionary dictionary];
12391151
[changes enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
12401152
serialized[key] = obj;
@@ -1249,12 +1161,11 @@ - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
12491161
*/
12501162
- (void)performOperation:(PFFieldOperation *)operation forKey:(NSString *)key {
12511163
@synchronized (lock) {
1252-
id newValue = [_estimatedData applyFieldOperation:operation forKey:key];
1164+
[_estimatedData applyFieldOperation:operation forKey:key];
12531165

12541166
PFFieldOperation *oldOperation = [[self unsavedChanges] objectForKey:key];
12551167
PFFieldOperation *newOperation = [operation mergeWithPrevious:oldOperation];
12561168
[[self unsavedChanges] setObject:newOperation forKey:key];
1257-
[self checkpointMutableContainer:newValue];
12581169
[_availableKeys addObject:key];
12591170
}
12601171
}
@@ -1320,7 +1231,6 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
13201231
state.updatedAt = other.updatedAt;
13211232
state.serverData = [other._state.serverData mutableCopy];
13221233
self._state = state;
1323-
[self checkpointAllMutableContainers];
13241234

13251235
dirty = NO;
13261236

@@ -1331,13 +1241,11 @@ - (PFObject *)mergeFromObject:(PFObject *)other {
13311241

13321242
- (void)_mergeAfterFetchWithResult:(NSDictionary *)result decoder:(PFDecoder *)decoder completeData:(BOOL)completeData {
13331243
@synchronized (lock) {
1334-
[self checkForChangesToMutableContainers];
13351244
[self _mergeFromServerWithResult:result decoder:decoder completeData:completeData];
13361245
if (completeData) {
13371246
[self removeOldKeysAfterFetch:result];
13381247
}
13391248
[self rebuildEstimatedData];
1340-
[self checkpointAllMutableContainers];
13411249
}
13421250
}
13431251

@@ -1366,16 +1274,12 @@ - (void)_mergeAfterSaveWithResult:(NSDictionary *)result decoder:(PFDecoder *)de
13661274
PFOperationSet *operationsForNextSave = operationSetQueue[0];
13671275
[operationsForNextSave mergeOperationSet:operationsBeforeSave];
13681276
} else {
1369-
// Merge the data from the save and the data from the server into serverData.
1370-
[self checkForChangesToMutableContainers];
1371-
13721277
PFMutableObjectState *state = [self._state mutableCopy];
13731278
[state applyOperationSet:operationsBeforeSave];
13741279
self._state = state;
13751280

13761281
[self _mergeFromServerWithResult:result decoder:decoder completeData:NO];
13771282
[self rebuildEstimatedData];
1378-
[self checkpointAllMutableContainers];
13791283
}
13801284
}
13811285
}
@@ -1409,7 +1313,6 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
14091313
} else if ([key isEqualToString:PFObjectACLRESTKey]) {
14101314
PFACL *acl = [PFACL ACLWithDictionary:obj];
14111315
[state setServerDataObject:acl forKey:key];
1412-
[self checkpointMutableContainer:acl];
14131316
} else {
14141317
[state setServerDataObject:[decoder decodeObject:obj] forKey:key];
14151318
}
@@ -1699,7 +1602,6 @@ - (instancetype)init {
16991602
_estimatedData = [PFObjectEstimatedData estimatedDataFromServerData:_pfinternal_state.serverData
17001603
operationSetQueue:operationSetQueue];
17011604
_availableKeys = [NSMutableSet set];
1702-
hashedObjectsCache = [[NSMutableDictionary alloc] init];
17031605
self.taskQueue = [[PFTaskQueue alloc] init];
17041606
_eventuallyTaskQueue = [[PFTaskQueue alloc] init];
17051607

@@ -2067,7 +1969,6 @@ - (BOOL)isDirty {
20671969

20681970
- (BOOL)isDirtyForKey:(NSString *)key {
20691971
@synchronized (lock) {
2070-
[self checkForChangesToMutableContainer:_estimatedData[key] forKey:key];
20711972
return !![[self unsavedChanges] objectForKey:key];
20721973
}
20731974
}
@@ -2312,7 +2213,6 @@ - (void)revert {
23122213
[_availableKeys intersectSet:persistentKeys];
23132214

23142215
[self rebuildEstimatedData];
2315-
[self checkpointAllMutableContainers];
23162216
}
23172217
}
23182218
}
@@ -2323,7 +2223,6 @@ - (void)revertObjectForKey:(NSString *)key {
23232223
[[self unsavedChanges] removeObjectForKey:key];
23242224
[self rebuildEstimatedData];
23252225
[_availableKeys removeObject:key];
2326-
[self checkpointAllMutableContainers];
23272226
}
23282227
}
23292228
}

Parse/PFUser.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,11 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
499499

500500
PFConsistencyAssert(!isCurrentUser, @"Attempt to merge currentUser with itself.");
501501

502-
[self checkForChangesToMutableContainers];
503502
@synchronized ([currentUser lock]) {
504503
NSString *oldUsername = [currentUser.username copy];
505504
NSString *oldPassword = [currentUser.password copy];
506505
NSArray *oldAnonymousData = currentUser.authData[PFAnonymousUserAuthenticationType];
507506

508-
[currentUser checkForChangesToMutableContainers];
509-
510507
// Move the changes to this object over to the currentUser object.
511508
PFOperationSet *selfOperations = operationSetQueue[0];
512509
[operationSetQueue removeAllObjects];

0 commit comments

Comments
 (0)