Skip to content

Use estimatedData for data availability #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions Parse/src/main/java/com/parse/ParseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ public String toString() {

// Cached State
private final Map<String, Object> estimatedData;
private final Map<String, Boolean> dataAvailability;
private final Map<Object, ParseJSONCacheItem> hashedObjects; // For mutable containers

private String localId;
Expand Down Expand Up @@ -385,7 +384,6 @@ public ParseObject(String theClassName) {
operationSetQueue.add(new ParseOperationSet());
estimatedData = new HashMap<>();
hashedObjects = new IdentityHashMap<>();
dataAvailability = new HashMap<>();

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

rebuildEstimatedData();
rebuildDataAvailability();
checkpointAllMutableContainers();
}
}
Expand Down Expand Up @@ -843,7 +840,6 @@ public Set<String> keySet() {
synchronized (mutex) {
currentOperations().remove(key);
rebuildEstimatedData();
rebuildDataAvailability();
checkpointAllMutableContainers();
}
}
Expand All @@ -856,7 +852,6 @@ public Set<String> keySet() {
synchronized (mutex) {
currentOperations().clear();
rebuildEstimatedData();
rebuildDataAvailability();
checkpointAllMutableContainers();
}
}
Expand Down Expand Up @@ -2959,18 +2954,6 @@ private void rebuildEstimatedData() {
}
}

/**
* Regenerates the dataAvailability map from the serverData.
*/
private void rebuildDataAvailability() {
synchronized (mutex) {
dataAvailability.clear();
for (String key : state.keySet()) {
dataAvailability.put(key, true);
}
}
}

/**
* performOperation() is like {@link #put(String, Object)} but instead of just taking a new value,
* it takes a ParseFieldOperation that modifies the value.
Expand All @@ -2990,7 +2973,6 @@ private void rebuildDataAvailability() {
currentOperations().put(key, newOperation);

checkpointMutableContainer(key, newValue);
dataAvailability.put(key, Boolean.TRUE);
}
}

Expand Down Expand Up @@ -3546,8 +3528,7 @@ public boolean isDataAvailable() {

private boolean isDataAvailable(String key) {
synchronized (mutex) {
return isDataAvailable()
|| (dataAvailability.containsKey(key) ? dataAvailability.get(key) : false);
return isDataAvailable() || estimatedData.containsKey(key);
}
}

Expand Down
11 changes: 11 additions & 0 deletions Parse/src/test/java/com/parse/ParseObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ParseObjectTest {

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

//region testGetter

@Test( expected = IllegalStateException.class )
public void testGetUnavailable() {
ParseObject.State state = mock(ParseObject.State.class);
when(state.className()).thenReturn("TestObject");
when(state.isComplete()).thenReturn(false);

ParseObject object = ParseObject.from(state);
object.get("foo");
}

@Test
public void testGetList() throws Exception {
ParseObject object = new ParseObject("Test");
Expand Down