Skip to content

Change Bound's before to inclusive #2981

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 4 commits into from
Sep 17, 2021
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

This is supposed to reduce confusion as to what before means for startAt() and endAt().

This is supposed to reduce confusion as to what  means for startAt() and endAt().
@schmidt-sebastian
Copy link
Contributor Author

cc @wu-hui

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 16, 2021

Coverage Report

Affected SDKs

  • firebase-firestore

    SDK overall coverage changed from 43.12% (d56db2a) to 43.11% (533749c0) by -0.01%.

    Filename Base (d56db2a) Head (533749c0) Diff
    AsyncQueue.java 77.00% 78.00% +1.00%
    Bound.java 56.36% 50.00% -6.36%
    BundleSerializer.java 89.12% 89.43% +0.31%
    RemoteSerializer.java 84.60% 84.63% +0.04%
    StructuredQuery.java 32.90% 32.44% -0.46%
    Target.java 97.06% 97.09% +0.03%

Test Logs

Notes

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

Head commit (533749c0) is created by Prow via merging commits: d56db2a 3e89c25.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 16, 2021

Binary Size Report

Affected SDKs

  • firebase-firestore

    Type Base (d56db2a) Head (533749c0) Diff
    aar 1.20 MB 1.20 MB +257 B (+0.0%)
    apk (release) 3.24 MB 3.24 MB +476 B (+0.0%)

Test Logs

Notes

Head commit (533749c0) is created by Prow via merging commits: d56db2a 3e89c25.

@schmidt-sebastian
Copy link
Contributor Author

This breaks the integration tests due to some logic change in regards to Bound.sortsBeforeDocument()

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

thanks for doing this!

@@ -976,8 +977,8 @@ public void testEncodesLimits() {
public void testEncodesBounds() {
Query q =
Query.atPath(ResourcePath.fromString("docs"))
.startAt(new Bound(asList(Values.refValue(databaseId, key("foo/bar"))), true))
.endAt(new Bound(asList(Values.refValue(databaseId, key("foo/baz"))), false));
.startAt(bound(true, refValue(databaseId, key("foo/bar"))))

Choose a reason for hiding this comment

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

optional: include code comment for true value here and throughout

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

return inclusive ? comparison <= 0 : comparison < 0;
}

/** Returns true if a document sorts after a bound using the provided sort order. */

Choose a reason for hiding this comment

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

readability request: can you include this comment somewhere in the class to save future us from going through this again?

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 (added an abbreviated version to isInclusive).

@@ -167,24 +167,35 @@ private int decodeLimit(JSONObject structuredQuery) {
}
}

private Bound decodeBound(@Nullable JSONObject bound) throws JSONException {
private Bound decodeStartAtBound(@Nullable JSONObject bound) throws JSONException {

Choose a reason for hiding this comment

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

Hm. I wonder if we can offload the duplicated logic into decodePosition, or if that just gets us back to the same level of misdirection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would need to somehow convey whether this is a start or end bound.

@@ -318,12 +318,14 @@ public String getCanonicalId() {

if (startAt != null) {
builder.append("|lb:");
builder.append(startAt.canonicalString());
builder.append(startAt.isInclusive() ? "b:" : "a:");

Choose a reason for hiding this comment

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

optional: move this ternary into a method on Bound.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The result is flipped depending on whether this is a startAt or endAt cursor, hence I pulled it out.

@@ -176,7 +178,7 @@ public void addIndexEntries(Document document) {
if (fieldIndex == null) return null;

Bound lowerBound = target.getLowerBound(fieldIndex);
String lowerBoundOp = lowerBound.isBefore() ? ">=" : ">"; // `startAt()` versus `startAfter()`
String lowerBoundOp = lowerBound.isInclusive() ? ">=" : ">";

Choose a reason for hiding this comment

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

this cleanness makes everything worth it.

@schmidt-sebastian schmidt-sebastian merged commit e445aca into master Sep 17, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/inclusive branch September 17, 2021 17:36
@firebase firebase locked and limited conversation to collaborators Oct 18, 2021
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