Skip to content

DeferredValue changes for ServerValue.increment() #1415

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 3 commits into from
Apr 2, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 1, 2020

Binary Size Report

Affected SDKs

SDKTypeBase (9e69d52)Head (2a37cb2)Diff
firebase-inappmessagingapk (aggressive)852132.00852122.00-10.00 (-0.00%)
protolite-well-known-typesapk (aggressive)122377.00122381.00+4.00 (+0.00%)
firebase-segmentationapk (aggressive)1017145.001017149.00+4.00 (+0.00%)
firebase-storageapk (aggressive)325641.00325638.00-3.00 (-0.00%)
firebase-crashlytics-ndkapk (aggressive)1170691.001170702.00+11.00 (+0.00%)
firebase-databaseapk (release)1101570.001101864.00+294.00 (+0.03%)
aar480458.00481591.00+1133.00 (+0.24%)
firebase-crashlyticsapk (aggressive)583647.00583653.00+6.00 (+0.00%)
firebase-installationsapk (aggressive)84598.0084602.00+4.00 (+0.00%)
firebase-dynamic-linksapk (aggressive)327465.00327463.00-2.00 (-0.00%)
firebase-installations-interopapk (aggressive)61714.0061718.00+4.00 (+0.01%)
firebase-componentsapk (aggressive)10960.0010964.00+4.00 (+0.04%)
firebase-abtapk (aggressive)85717.0085706.00-11.00 (-0.01%)
firebase-configapk (aggressive)395817.00395821.00+4.00 (+0.00%)
firebase-datatransportapk (aggressive)116364.00116368.00+4.00 (+0.00%)
firebase-inappmessaging-displayapk (aggressive)1813854.001813859.00+5.00 (+0.00%)
firebase-functionsapk (aggressive)393465.00393476.00+11.00 (+0.00%)
firebase-database-collectionapk (aggressive)313622.00313609.00-13.00 (-0.00%)
firebase-firestoreapk (aggressive)443191.00443193.00+2.00 (+0.00%)
baseapk (aggressive)10661.0010680.00+19.00 (+0.18%)
Metric Unit: byte

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 1, 2020

Coverage Report

Affected SDKs

SDKTypeBase (9e69d52)Head (2a37cb2)Diff
firebase-database?0.51? (?)
ChildChangeAccumulator.java?0.84? (?)
NodeUtilities.java?0.74? (?)
Utilities.java?0.69? (?)
ListenHashProvider.java?0.00? (?)
150 more entries not displayed here ...
firebase-database-ktx?0.86? (?)
Database.kt?0.86? (?)
Metric Unit: percentage

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage. Report files are located at <product-build-dir>/reports/jacoco/.

Copy link
Member

@inlined inlined left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted with comments.

public void testServerIncrementOverwritesExistingData()
public void testServerIncrementOverwritesExistingDataOnline()
throws DatabaseException, TimeoutException, InterruptedException {
serverIncrementOverwritesExistingData(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: boolean values should typically be named. E.g. serverIncrementOverwritesExistingData(/*online*/ true);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Android Studio does this already implicitly, but it still makes sense to do until GitHub catches up.

import java.util.ArrayList;

/** A DeferredValueProvider computes the value of a Node only when {@link #node()} is invoked. */
public class DeferredValueProvider implements ValueProvider {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could reduce the number of files that people need to read if you have

ValueProvider
ValueProvider::Deferred
ValueProvider::Existing

IDR if that requires you to make an abstract class rather than an interface though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but I think it is still a good idea - especially since these classes are so small.

if (!value.equals(data.getValue()) || !priority.equals(data.getPriority())) {
return NodeUtilities.NodeFromJSON(value, priority);
Object value = resolveDeferredLeafValue(data.getValue(), existing, serverValues);
if (!value.equals(data.getValue()) || !Utilities.equals(priority, rawPriority)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof... I hate files and classes called utilities

} else {
return holder.getRootNode();
}
}
}

public static CompoundWrite resolveDeferredValueMerge(
CompoundWrite merge, Node existing, final Map<String, Object> serverValues) {
CompoundWrite merge, SyncTree syncTree, Path path, final Map<String, Object> serverValues) {
CompoundWrite write = CompoundWrite.emptyWrite();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. In iOS this starts as merge and is modified with addWrite only where the resolved value changes. Is this a pessimisation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to make it match iOS just now but it broke a bunch of tests.

@@ -249,12 +249,12 @@ public boolean isEmpty() {
if (write.isOverwrite()) {
Node resolvedNode =
ServerValues.resolveDeferredValueSnapshot(
write.getOverwrite(), existing, serverValues);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can delete "existing" above.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. This also removed:

ArrayList<Long> excludeThis = new ArrayList<>();
excludeThis.add(write.getWriteId());
calcCompleteEventCache(write.getPath(), excludeThis);

That's a bit suspicious, but this never existed on iOS.

@schmidt-sebastian schmidt-sebastian merged commit 068ca6f into master Apr 2, 2020
@firebase firebase locked and limited conversation to collaborators May 2, 2020
@kaibolay kaibolay deleted the mrschmidt/increment branch September 14, 2022 17:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants