Skip to content

Commit a9df669

Browse files
committed
Remove mutable container tracking
Resolves #58
1 parent 2ee74c4 commit a9df669

File tree

4 files changed

+0
-152
lines changed

4 files changed

+0
-152
lines changed

Parse/src/main/java/com/parse/ParseJSONCacheItem.java

-40
This file was deleted.

Parse/src/main/java/com/parse/ParseObject.java

-96
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Date;
2222
import java.util.HashMap;
2323
import java.util.HashSet;
24-
import java.util.IdentityHashMap;
2524
import java.util.Iterator;
2625
import java.util.LinkedList;
2726
import java.util.List;
@@ -306,7 +305,6 @@ public String toString() {
306305

307306
// Cached State
308307
private final Map<String, Object> estimatedData;
309-
private final Map<Object, ParseJSONCacheItem> hashedObjects; // For mutable containers
310308

311309
private String localId;
312310
private final ParseMulticastDelegate<ParseObject> saveEvent = new ParseMulticastDelegate<>();
@@ -383,7 +381,6 @@ public ParseObject(String theClassName) {
383381
operationSetQueue = new LinkedList<>();
384382
operationSetQueue.add(new ParseOperationSet());
385383
estimatedData = new HashMap<>();
386-
hashedObjects = new IdentityHashMap<>();
387384

388385
State.Init<?> builder = newStateBuilder(theClassName);
389386
// When called from new, assume hasData for the whole object is true.
@@ -615,16 +612,6 @@ public Void then(Task<Void> task) throws Exception {
615612
}
616613
}
617614

618-
private void addToHashedObjects(Object object) {
619-
synchronized (mutex) {
620-
try {
621-
hashedObjects.put(object, new ParseJSONCacheItem(object));
622-
} catch (JSONException e) {
623-
throw new IllegalArgumentException("Couldn't serialize container value to JSON.");
624-
}
625-
}
626-
}
627-
628615
/**
629616
* Converts a {@code ParseObject.State} to a {@code ParseObject}.
630617
*
@@ -752,7 +739,6 @@ private void setState(State newState, boolean notifyIfObjectIdChanges) {
752739
}
753740

754741
rebuildEstimatedData();
755-
checkpointAllMutableContainers();
756742
}
757743
}
758744

@@ -840,7 +826,6 @@ public Set<String> keySet() {
840826
synchronized (mutex) {
841827
currentOperations().remove(key);
842828
rebuildEstimatedData();
843-
checkpointAllMutableContainers();
844829
}
845830
}
846831

@@ -852,7 +837,6 @@ public Set<String> keySet() {
852837
synchronized (mutex) {
853838
currentOperations().clear();
854839
rebuildEstimatedData();
855-
checkpointAllMutableContainers();
856840
}
857841
}
858842

@@ -1026,8 +1010,6 @@ protected boolean visit(Object object) {
10261010

10271011
/* package */ JSONObject toRest(
10281012
State state, List<ParseOperationSet> operationSetQueue, ParseEncoder objectEncoder) {
1029-
checkForChangesToMutableContainers();
1030-
10311013
// Public data goes in dataJSON; special fields go in objectJSON.
10321014
JSONObject json = new JSONObject();
10331015

@@ -1177,7 +1159,6 @@ public boolean isDirty() {
11771159

11781160
/* package */ boolean isDirty(boolean considerChildren) {
11791161
synchronized (mutex) {
1180-
checkForChangesToMutableContainers();
11811162
return (isDeleted || getObjectId() == null || hasChanges() || (considerChildren && hasDirtyChildren()));
11821163
}
11831164
}
@@ -1212,80 +1193,6 @@ public boolean isDirty(String key) {
12121193
}
12131194
}
12141195

1215-
//region Mutable Containers
1216-
1217-
/* package */ boolean isContainerObject(String key, Object object) {
1218-
return (object instanceof JSONObject || object instanceof JSONArray
1219-
|| object instanceof Map || object instanceof List
1220-
|| object instanceof ParseACL || object instanceof ParseGeoPoint);
1221-
}
1222-
1223-
/**
1224-
* Updates the JSON cache value for all of the values in estimatedData.
1225-
*/
1226-
private void checkpointAllMutableContainers() {
1227-
synchronized (mutex) {
1228-
for (Map.Entry<String, Object> entry : estimatedData.entrySet()) {
1229-
checkpointMutableContainer(entry.getKey(), entry.getValue());
1230-
}
1231-
}
1232-
}
1233-
1234-
/**
1235-
* Updates the JSON cache value for the given object.
1236-
*/
1237-
private void checkpointMutableContainer(String key, Object object) {
1238-
synchronized (mutex) {
1239-
if (isContainerObject(key, object)) {
1240-
addToHashedObjects(object);
1241-
}
1242-
}
1243-
}
1244-
1245-
/**
1246-
* Inspects to see if a given mutable container owned by this object has been mutated, and treats
1247-
* any mutation as a new {@link #put(String, Object)} call.
1248-
*/
1249-
private void checkForChangesToMutableContainer(String key, Object object) {
1250-
synchronized (mutex) {
1251-
if (isContainerObject(key, object)) {
1252-
ParseJSONCacheItem oldCacheItem = hashedObjects.get(object);
1253-
if (oldCacheItem == null) {
1254-
throw new IllegalArgumentException(
1255-
"ParseObject contains container item that isn't cached.");
1256-
} else {
1257-
ParseJSONCacheItem newCacheItem;
1258-
try {
1259-
newCacheItem = new ParseJSONCacheItem(object);
1260-
} catch (JSONException e) {
1261-
throw new RuntimeException(e);
1262-
}
1263-
if (!oldCacheItem.equals(newCacheItem)) {
1264-
// A mutable container changed out from under us. Treat it as a set operation.
1265-
performOperation(key, new ParseSetOperation(object));
1266-
}
1267-
}
1268-
} else {
1269-
hashedObjects.remove(object);
1270-
}
1271-
}
1272-
}
1273-
1274-
/**
1275-
* Inspects to see if any mutable container owned by this object has been mutated, and treats any
1276-
* mutation as a new {@link #put(String, Object)} call.
1277-
*/
1278-
/* package */ void checkForChangesToMutableContainers() {
1279-
synchronized (mutex) {
1280-
for (String key : estimatedData.keySet()) {
1281-
checkForChangesToMutableContainer(key, estimatedData.get(key));
1282-
}
1283-
hashedObjects.keySet().retainAll(estimatedData.values());
1284-
}
1285-
}
1286-
1287-
//endregion
1288-
12891196
/**
12901197
* Accessor to the object id. An object id is assigned as soon as an object is saved to the
12911198
* server. The combination of a className and an objectId uniquely identifies an object in your
@@ -2971,8 +2878,6 @@ private void rebuildEstimatedData() {
29712878
ParseFieldOperation oldOperation = currentOperations().get(key);
29722879
ParseFieldOperation newOperation = operation.mergeWithPrevious(oldOperation);
29732880
currentOperations().put(key, newOperation);
2974-
2975-
checkpointMutableContainer(key, newValue);
29762881
}
29772882
}
29782883

@@ -3500,7 +3405,6 @@ private ParseACL getACL(boolean mayCopy) {
35003405
if (mayCopy && ((ParseACL) acl).isShared()) {
35013406
ParseACL copy = ((ParseACL) acl).copy();
35023407
estimatedData.put(KEY_ACL, copy);
3503-
addToHashedObjects(copy);
35043408
return copy;
35053409
}
35063410
return (ParseACL) acl;

Parse/src/main/java/com/parse/ParseUser.java

-12
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,6 @@ boolean isKeyMutable(String key) {
194194
}
195195
}
196196

197-
@Override
198-
boolean isContainerObject(String key, Object object) {
199-
if (KEY_AUTH_DATA.equals(key)) {
200-
// We're tracking dirtiness of `authData` ourselves.
201-
return false;
202-
}
203-
return super.isContainerObject(key, object);
204-
}
205-
206197
/**
207198
* Whether the ParseUser has been authenticated on this device. This will be true if the ParseUser
208199
* was obtained via a logIn or signUp method. Only an authenticated ParseUser can be saved (with
@@ -623,9 +614,6 @@ public Task<Void> then(Task<Void> task) throws Exception {
623614
new IllegalArgumentException("Attempt to merge currentUser with itself."));
624615
}
625616

626-
checkForChangesToMutableContainers();
627-
user.checkForChangesToMutableContainers();
628-
629617
boolean isLazy = user.isLazy();
630618
final String oldUsername = user.getUsername();
631619
final String oldPassword = user.getPassword();

Parse/src/test/java/com/parse/ParseUserTest.java

-4
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUser() throws Exception {
242242
Task<Void> signUpTask = user.signUpAsync(Task.<Void>forResult(null));
243243
signUpTask.waitForCompletion();
244244

245-
// Make sure we checkForChangesToMutableContainers
246-
verify(currentUser, times(1)).checkForChangesToMutableContainers();
247245
// Make sure currentUser copy changes from user
248246
verify(currentUser, times(1)).copyChangesFrom(user);
249247
// Make sure we update currentUser username and password
@@ -289,8 +287,6 @@ public void testSignUpAsyncWithMergeInDiskAnonymousUserSaveFailure() throws Exce
289287
Task<Void> signUpTask = user.signUpAsync(Task.<Void>forResult(null));
290288
signUpTask.waitForCompletion();
291289

292-
// Make sure we checkForChangesToMutableContainers
293-
verify(partialMockCurrentUser, times(1)).checkForChangesToMutableContainers();
294290
// Make sure we update currentUser username and password
295291
verify(partialMockCurrentUser, times(1)).setUsername("userName");
296292
verify(partialMockCurrentUser, times(1)).setPassword("password");

0 commit comments

Comments
 (0)