Skip to content

Commit bf4bab2

Browse files
committed
Remove mutable container tracking
Resolves #58
1 parent 0e71f10 commit bf4bab2

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

@@ -847,7 +833,6 @@ public void revert(String key) {
847833
if (isDirty(key)) {
848834
currentOperations().remove(key);
849835
rebuildEstimatedData();
850-
checkpointAllMutableContainers();
851836
}
852837
}
853838
}
@@ -861,7 +846,6 @@ public void revert() {
861846
if (isDirty()) {
862847
currentOperations().clear();
863848
rebuildEstimatedData();
864-
checkpointAllMutableContainers();
865849
}
866850
}
867851
}
@@ -1036,8 +1020,6 @@ protected boolean visit(Object object) {
10361020

10371021
/* package */ JSONObject toRest(
10381022
State state, List<ParseOperationSet> operationSetQueue, ParseEncoder objectEncoder) {
1039-
checkForChangesToMutableContainers();
1040-
10411023
// Public data goes in dataJSON; special fields go in objectJSON.
10421024
JSONObject json = new JSONObject();
10431025

@@ -1187,7 +1169,6 @@ public boolean isDirty() {
11871169

11881170
/* package */ boolean isDirty(boolean considerChildren) {
11891171
synchronized (mutex) {
1190-
checkForChangesToMutableContainers();
11911172
return (isDeleted || getObjectId() == null || hasChanges() || (considerChildren && hasDirtyChildren()));
11921173
}
11931174
}
@@ -1222,80 +1203,6 @@ public boolean isDirty(String key) {
12221203
}
12231204
}
12241205

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

@@ -3512,7 +3417,6 @@ private ParseACL getACL(boolean mayCopy) {
35123417
if (mayCopy && ((ParseACL) acl).isShared()) {
35133418
ParseACL copy = ((ParseACL) acl).copy();
35143419
estimatedData.put(KEY_ACL, copy);
3515-
addToHashedObjects(copy);
35163420
return copy;
35173421
}
35183422
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
@@ -637,9 +628,6 @@ public Task<Void> then(Task<Void> task) throws Exception {
637628
new IllegalArgumentException("Attempt to merge currentUser with itself."));
638629
}
639630

640-
checkForChangesToMutableContainers();
641-
user.checkForChangesToMutableContainers();
642-
643631
boolean isLazy = user.isLazy();
644632
final String oldUsername = user.getUsername();
645633
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)