Skip to content

Commit 844b4ca

Browse files
fix: Do not send page size with auto-paginate. Fixes warnings in listCollections and listDocuments. (#2336)
* fix: Do not send page size with auto-paginate. * Remove page size for listCollections and update unit tests
1 parent 9ac0394 commit 844b4ca

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

dev/src/reference/collection-reference.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ export class CollectionReference<
183183
parent: parentPath.formattedName,
184184
collectionId: this.id,
185185
showMissing: true,
186-
// Setting `pageSize` to an arbitrarily large value lets the backend cap
187-
// the page size (currently to 300). Note that the backend rejects
188-
// MAX_INT32 (b/146883794).
189-
pageSize: Math.pow(2, 16) - 1,
190186
mask: {fieldPaths: []},
191187
};
192188

dev/src/reference/document-reference.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ export class DocumentReference<
267267
return this.firestore.initializeIfNeeded(tag).then(() => {
268268
const request: api.IListCollectionIdsRequest = {
269269
parent: this.formattedName,
270-
// Setting `pageSize` to an arbitrarily large value lets the backend cap
271-
// the page size (currently to 300). Note that the backend rejects
272-
// MAX_INT32 (b/146883794).
273-
pageSize: Math.pow(2, 16) - 1,
274270
};
275271
return this._firestore
276272
.request<

dev/system-test/firestore.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,25 @@ describe('CollectionReference class', () => {
783783
expect(missingDocs.map(doc => doc.id)).to.have.members(['b']);
784784
});
785785

786+
it('lists documents (more than the max page size)', async () => {
787+
const batch = firestore.batch();
788+
const expectedResults = [];
789+
for (let i = 0; i < 400; i++) {
790+
const docRef = randomCol.doc(`${i}`.padStart(3, '0'));
791+
batch.set(docRef, {id: i});
792+
expectedResults.push(docRef.id);
793+
}
794+
await batch.commit();
795+
796+
const documentRefs = await randomCol.listDocuments();
797+
798+
const actualDocIds = documentRefs
799+
.map(dr => dr.id)
800+
.sort((a, b) => a.localeCompare(b));
801+
802+
expect(actualDocIds).to.deep.equal(expectedResults);
803+
});
804+
786805
it('supports withConverter()', async () => {
787806
const ref = await firestore
788807
.collection('col')
@@ -1176,11 +1195,13 @@ describe('DocumentReference class', () => {
11761195
});
11771196

11781197
it('has listCollections() method', () => {
1179-
const collections = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
1198+
const collections: string[] = [];
11801199
const promises: Array<Promise<{}>> = [];
11811200

1182-
for (const collection of collections) {
1183-
promises.push(randomCol.doc(`doc/${collection}/doc`).create({}));
1201+
for (let i = 0; i < 400; i++) {
1202+
const collectionId = i.toString().padStart(3, '0');
1203+
promises.push(randomCol.doc(`doc/${collectionId}/doc`).create({}));
1204+
collections.push(collectionId);
11841205
}
11851206

11861207
return Promise.all(promises)

dev/test/collection.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ describe('Collection interface', () => {
156156
parent: `${DATABASE_ROOT}/documents/a/b`,
157157
collectionId: 'c',
158158
showMissing: true,
159-
pageSize: 65535,
160159
mask: {fieldPaths: []},
161160
});
162161

dev/test/document.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,6 @@ describe('listCollections() method', () => {
22232223
listCollectionIds: request => {
22242224
expect(request).to.deep.eq({
22252225
parent: `projects/${PROJECT_ID}/databases/(default)/documents/coll/doc`,
2226-
pageSize: 65535,
22272226
});
22282227

22292228
return response(['second', 'first']);

dev/test/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,6 @@ describe('listCollections() method', () => {
10641064
listCollectionIds: request => {
10651065
expect(request).to.deep.eq({
10661066
parent: `projects/${PROJECT_ID}/databases/(default)/documents`,
1067-
pageSize: 65535,
10681067
});
10691068

10701069
return response(['first', 'second']);

0 commit comments

Comments
 (0)