Skip to content

Commit 86248b4

Browse files
committed
Remove mutable container tracking
Resolves #58
1 parent 70f5c20 commit 86248b4

File tree

4 files changed

+0
-151
lines changed

4 files changed

+0
-151
lines changed

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

-40
This file was deleted.

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

-95
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;
@@ -307,7 +306,6 @@ public String toString() {
307306
// Cached State
308307
private final Map<String, Object> estimatedData;
309308
private final Map<String, Boolean> dataAvailability;
310-
private final Map<Object, ParseJSONCacheItem> hashedObjects; // For mutable containers
311309

312310
private String localId;
313311
private final ParseMulticastDelegate<ParseObject> saveEvent = new ParseMulticastDelegate<>();
@@ -384,7 +382,6 @@ public ParseObject(String theClassName) {
384382
operationSetQueue = new LinkedList<>();
385383
operationSetQueue.add(new ParseOperationSet());
386384
estimatedData = new HashMap<>();
387-
hashedObjects = new IdentityHashMap<>();
388385
dataAvailability = new HashMap<>();
389386

390387
State.Init<?> builder = newStateBuilder(theClassName);
@@ -617,16 +614,6 @@ public Void then(Task<Void> task) throws Exception {
617614
}
618615
}
619616

620-
private void addToHashedObjects(Object object) {
621-
synchronized (mutex) {
622-
try {
623-
hashedObjects.put(object, new ParseJSONCacheItem(object));
624-
} catch (JSONException e) {
625-
throw new IllegalArgumentException("Couldn't serialize container value to JSON.");
626-
}
627-
}
628-
}
629-
630617
/**
631618
* Converts a {@code ParseObject.State} to a {@code ParseObject}.
632619
*
@@ -755,7 +742,6 @@ private void setState(State newState, boolean notifyIfObjectIdChanges) {
755742

756743
rebuildEstimatedData();
757744
rebuildDataAvailability();
758-
checkpointAllMutableContainers();
759745
}
760746
}
761747

@@ -844,7 +830,6 @@ public Set<String> keySet() {
844830
currentOperations().remove(key);
845831
rebuildEstimatedData();
846832
rebuildDataAvailability();
847-
checkpointAllMutableContainers();
848833
}
849834
}
850835

@@ -857,7 +842,6 @@ public Set<String> keySet() {
857842
currentOperations().clear();
858843
rebuildEstimatedData();
859844
rebuildDataAvailability();
860-
checkpointAllMutableContainers();
861845
}
862846
}
863847

@@ -1031,8 +1015,6 @@ protected boolean visit(Object object) {
10311015

10321016
/* package */ JSONObject toRest(
10331017
State state, List<ParseOperationSet> operationSetQueue, ParseEncoder objectEncoder) {
1034-
checkForChangesToMutableContainers();
1035-
10361018
// Public data goes in dataJSON; special fields go in objectJSON.
10371019
JSONObject json = new JSONObject();
10381020

@@ -1182,7 +1164,6 @@ public boolean isDirty() {
11821164

11831165
/* package */ boolean isDirty(boolean considerChildren) {
11841166
synchronized (mutex) {
1185-
checkForChangesToMutableContainers();
11861167
return (isDeleted || getObjectId() == null || hasChanges() || (considerChildren && hasDirtyChildren()));
11871168
}
11881169
}
@@ -1217,80 +1198,6 @@ public boolean isDirty(String key) {
12171198
}
12181199
}
12191200

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

2992-
checkpointMutableContainer(key, newValue);
29932899
dataAvailability.put(key, Boolean.TRUE);
29942900
}
29952901
}
@@ -3518,7 +3424,6 @@ private ParseACL getACL(boolean mayCopy) {
35183424
if (mayCopy && ((ParseACL) acl).isShared()) {
35193425
ParseACL copy = ((ParseACL) acl).copy();
35203426
estimatedData.put(KEY_ACL, copy);
3521-
addToHashedObjects(copy);
35223427
return copy;
35233428
}
35243429
return (ParseACL) acl;

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

-12
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,6 @@ boolean isKeyMutable(String key) {
191191
}
192192
}
193193

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

624-
checkForChangesToMutableContainers();
625-
user.checkForChangesToMutableContainers();
626-
627615
boolean isLazy = user.isLazy();
628616
final String oldUsername = user.getUsername();
629617
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)