Google cloud platform Google数据存储分页
我试图使用游标实现分页,但当我尝试使用在第一次查询(查询10条记录)后返回的endCursor时,它会给我一个错误“无效编码”。顺便说一下,我一共有16张唱片。我希望在下一次查询中,它会给出最后6条记录 这是我的密码:Google cloud platform Google数据存储分页,google-cloud-platform,google-cloud-datastore,Google Cloud Platform,Google Cloud Datastore,我试图使用游标实现分页,但当我尝试使用在第一次查询(查询10条记录)后返回的endCursor时,它会给我一个错误“无效编码”。顺便说一下,我一共有16张唱片。我希望在下一次查询中,它会给出最后6条记录 这是我的密码: router.get("/scan/history/query", async (req: Request, resp: Response) => { const userId = resp.locals.user && resp.l
router.get("/scan/history/query", async (req: Request, resp: Response) => {
const userId = resp.locals.user && resp.locals.user.sub
const pageCursor = req.query.cursor
if (userId) {
let mainQuery = dataStoreClient.createQuery(process.env.GOOGLE_DATASTORE_KIND_SCAN_RESULTS)
.filter("userId", QUERY_FILTER_OPERATORS.EQUAL, userId)
.filter("isDeletedDocument", QUERY_FILTER_OPERATORS.EQUAL, false)
.select(["__key__", "scanDate", "scanKeyword", "scanFilter",
"hasRecord", "scanThreatStatus", "scanDuration",
"scanType", "scanStatus", "domainName"])
.order("scanDate", { descending: true })
.limit(10)
if (pageCursor) {
mainQuery = mainQuery.start(pageCursor)
}
const results = await mainQuery.run()
const entities = results[0]
const info = results[1]
const hasNextPage = info.moreResults !== "NO_MORE_RESULTS"
const pageResult = new PageResult(entities, info.endCursor, hasNextPage)
return HttpResult.Ok(resp, pageResult)
}
return HttpResult.UriNotFound(resp)
})
更新:
我尝试了数千张唱片,但我的限制仍然是10张。它非常适合2或3个查询,但当我第四次尝试查询时,它会向我抛出一个错误“无效编码”我知道这是旧的,但如果其他人遇到这个问题(就像我刚才做的那样),我可以通过使用
encodeURIComponent()
对光标值进行编码来解决它。看起来光标值偶尔会包含+
字符,如果在URL中未转义,则会导致问题能否编辑代码以显示如何获取、存储和检索页面光标?目前,为了进行测试,我将返回页面光标以及实体作为api响应。然后,我将pageCursor用作下一条记录的下一个api调用的查询字符串。在检查下一个pageCursor之前,您不会等待查询完成。在您读取内容时,内容可能正在更改,从而导致值损坏。是否使用wait-different。然后(function())?