Skip to content

Accept Proto3 JSON limits in Bundled Queries #2463

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
Feb 24, 2021
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
6 changes: 5 additions & 1 deletion firebase-firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Unreleased (22.1.0)
# Unreleased (22.1.1)
- [fixed] Fixed an issue that dropped the limit for queries loaded from
Bundles that were generated by the NodeJS SDK.

# 22.10
- [feature] Added support for Firestore Bundles via
`FirebaseFirestore.loadBundle()` and `FirebaseFirestore.getNamedQuery()`.
Bundles contain pre-packaged data produced with the NodeJS Server SDK and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ private BundledQuery decodeBundledQuery(JSONObject bundledQuery) throws JSONExce

private int decodeLimit(JSONObject structuredQuery) {
JSONObject limit = structuredQuery.optJSONObject("limit");
return limit != null ? limit.optInt("value", -1) : -1;

if (limit != null) {
return limit.optInt("value", -1); // ProtobufJS
} else {
return structuredQuery.optInt("limit", -1); // Proto3 JSON
}
}

private Bound decodeBound(@Nullable JSONObject bound) throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,16 @@ public void testDecodeOrderByQuery() throws JSONException {

@Test
public void testDecodesLimitQuery() throws JSONException {
String json = "{ from: [ { collectionId: 'coll' } ], limit: { value: 5 } }";
Query query = TestUtil.query("coll").limitToFirst(5);
assertDecodesNamedQuery(json, query);
String[] json =
new String[] {
"{ from: [ { collectionId: 'coll' } ], limit: { value: 5 } }", // ProtobufJS
"{ from: [ { collectionId: 'coll' } ], limit: 5 }" // Proto3 JSON
};

for (String encoded : json) {
Query query = TestUtil.query("coll").limitToFirst(5);
assertDecodesNamedQuery(encoded, query);
}
}

@Test
Expand Down