firebase / firebase/firebase-admin-node

Firebase query orderByKey().limitToFirst(n).startAfter() returns n-1 items iso n

未关闭
#2,350 4 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
api: database
主要语言
TypeScript
星标
1.7k
派生
419
平均合并
3 天 10 小时
30 天内合并 PR
16

描述

### [READ] Step 1: Are you in the right place?
yes

### [REQUIRED] Step 2: Describe your environment

* Operating System version: Ubuntu 22.04 lts
* Firebase SDK version: 11.11.0
* Firebase Product: realtime database (auth, database, storage, etc)
* Node.js version: 16.20.2
* NPM version: 8.19.4

### [REQUIRED] Step 3: Describe the problem

Firebase query of type:
`admin.database.Database.ref('collection').orderByKey().limitToFirst(100).startAfter(lastKey)` only returns 99 items iso 100 even if more keys are in the firebase realtime database.

On version 11.4.1 of firebase-admin this query behaves as expected and 100 items are returned.

#### Steps to reproduce:

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

#### Relevant Code:

```typescript
let query;
let lastDocument = null;
let lastBatchSize: number = 100;

while (lastBatchSize === 100) {
query = database.ref('collection').orderByKey()
.limitToFirst(100);

if (lastDocument !== null) {
query = query.startAfter(lastDocument.key);
}

const snapshot = await query.get();
const keys = Object.keys(snapshot.val() || {});
const docs = keys.map((key) => snapshot.child(key));

if (docs.length === 0) break;
console.log("docs length " + docs.length); //prints 99 on 11.11.0, prints 100 on 11.4.1

if (docs.length) {
lastDocument = docs[docs.length - 1];
}
lastBatchSize = docs.length;
}
```

贡献指南

打开贡献指南

调研方向

从 issue 中所示的 admin.database.Database.ref 查询链开始,重点关注 orderByKey()、limitToFirst() 和 startAfter()。使用提供的分页循环复现 SDK 11.11.0 与 11.4.1 之间的差异。当剩余键足够时,请求返回 lastDocument.key 之后 100 个项目的查询应返回 100 个项目,并为该回归问题提供覆盖,这即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
firebase, node.js, typescript
领域
databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。