Skip to content

Commit 2ee74c4

Browse files
committed
Merge pull request #107 from ParsePlatform/grantland.data_availability
Use estimatedData for data availability
2 parents 49d1a29 + 537b389 commit 2ee74c4

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ public String toString() {
306306

307307
// Cached State
308308
private final Map<String, Object> estimatedData;
309-
private final Map<String, Boolean> dataAvailability;
310309
private final Map<Object, ParseJSONCacheItem> hashedObjects; // For mutable containers
311310

312311
private String localId;
@@ -385,7 +384,6 @@ public ParseObject(String theClassName) {
385384
operationSetQueue.add(new ParseOperationSet());
386385
estimatedData = new HashMap<>();
387386
hashedObjects = new IdentityHashMap<>();
388-
dataAvailability = new HashMap<>();
389387

390388
State.Init<?> builder = newStateBuilder(theClassName);
391389
// When called from new, assume hasData for the whole object is true.
@@ -754,7 +752,6 @@ private void setState(State newState, boolean notifyIfObjectIdChanges) {
754752
}
755753

756754
rebuildEstimatedData();
757-
rebuildDataAvailability();
758755
checkpointAllMutableContainers();
759756
}
760757
}
@@ -843,7 +840,6 @@ public Set<String> keySet() {
843840
synchronized (mutex) {
844841
currentOperations().remove(key);
845842
rebuildEstimatedData();
846-
rebuildDataAvailability();
847843
checkpointAllMutableContainers();
848844
}
849845
}
@@ -856,7 +852,6 @@ public Set<String> keySet() {
856852
synchronized (mutex) {
857853
currentOperations().clear();
858854
rebuildEstimatedData();
859-
rebuildDataAvailability();
860855
checkpointAllMutableContainers();
861856
}
862857
}
@@ -2959,18 +2954,6 @@ private void rebuildEstimatedData() {
29592954
}
29602955
}
29612956

2962-
/**
2963-
* Regenerates the dataAvailability map from the serverData.
2964-
*/
2965-
private void rebuildDataAvailability() {
2966-
synchronized (mutex) {
2967-
dataAvailability.clear();
2968-
for (String key : state.keySet()) {
2969-
dataAvailability.put(key, true);
2970-
}
2971-
}
2972-
}
2973-
29742957
/**
29752958
* performOperation() is like {@link #put(String, Object)} but instead of just taking a new value,
29762959
* it takes a ParseFieldOperation that modifies the value.
@@ -2990,7 +2973,6 @@ private void rebuildDataAvailability() {
29902973
currentOperations().put(key, newOperation);
29912974

29922975
checkpointMutableContainer(key, newValue);
2993-
dataAvailability.put(key, Boolean.TRUE);
29942976
}
29952977
}
29962978

@@ -3546,8 +3528,7 @@ public boolean isDataAvailable() {
35463528

35473529
private boolean isDataAvailable(String key) {
35483530
synchronized (mutex) {
3549-
return isDataAvailable()
3550-
|| (dataAvailability.containsKey(key) ? dataAvailability.get(key) : false);
3531+
return isDataAvailable() || estimatedData.containsKey(key);
35513532
}
35523533
}
35533534

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.junit.Assert.assertNull;
2828
import static org.junit.Assert.assertTrue;
2929
import static org.mockito.Mockito.mock;
30+
import static org.mockito.Mockito.when;
3031

3132
public class ParseObjectTest {
3233

@@ -73,6 +74,16 @@ public void testFromJSONPayloadWithoutClassname() throws JSONException {
7374

7475
//region testGetter
7576

77+
@Test( expected = IllegalStateException.class )
78+
public void testGetUnavailable() {
79+
ParseObject.State state = mock(ParseObject.State.class);
80+
when(state.className()).thenReturn("TestObject");
81+
when(state.isComplete()).thenReturn(false);
82+
83+
ParseObject object = ParseObject.from(state);
84+
object.get("foo");
85+
}
86+
7687
@Test
7788
public void testGetList() throws Exception {
7889
ParseObject object = new ParseObject("Test");

0 commit comments

Comments
 (0)