Skip to content

Commit ce1a078

Browse files
Accept Proto3 JSON limits in Bundled Queries (#2463)
1 parent 7b9b80e commit ce1a078

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

firebase-firestore/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Unreleased (22.1.0)
1+
# Unreleased (22.1.1)
2+
- [fixed] Fixed an issue that dropped the limit for queries loaded from
3+
Bundles that were generated by the NodeJS SDK.
4+
5+
# 22.10
26
- [feature] Added support for Firestore Bundles via
37
`FirebaseFirestore.loadBundle()` and `FirebaseFirestore.getNamedQuery()`.
48
Bundles contain pre-packaged data produced with the NodeJS Server SDK and

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleSerializer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ private BundledQuery decodeBundledQuery(JSONObject bundledQuery) throws JSONExce
162162

163163
private int decodeLimit(JSONObject structuredQuery) {
164164
JSONObject limit = structuredQuery.optJSONObject("limit");
165-
return limit != null ? limit.optInt("value", -1) : -1;
165+
166+
if (limit != null) {
167+
return limit.optInt("value", -1); // ProtobufJS
168+
} else {
169+
return structuredQuery.optInt("limit", -1); // Proto3 JSON
170+
}
166171
}
167172

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

firebase-firestore/src/test/java/com/google/firebase/firestore/bundle/BundleSerializerTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,16 @@ public void testDecodeOrderByQuery() throws JSONException {
553553

554554
@Test
555555
public void testDecodesLimitQuery() throws JSONException {
556-
String json = "{ from: [ { collectionId: 'coll' } ], limit: { value: 5 } }";
557-
Query query = TestUtil.query("coll").limitToFirst(5);
558-
assertDecodesNamedQuery(json, query);
556+
String[] json =
557+
new String[] {
558+
"{ from: [ { collectionId: 'coll' } ], limit: { value: 5 } }", // ProtobufJS
559+
"{ from: [ { collectionId: 'coll' } ], limit: 5 }" // Proto3 JSON
560+
};
561+
562+
for (String encoded : json) {
563+
Query query = TestUtil.query("coll").limitToFirst(5);
564+
assertDecodesNamedQuery(encoded, query);
565+
}
559566
}
560567

561568
@Test

0 commit comments

Comments
 (0)