Skip to content

fix(objectql): findData 返回真实 total/hasMore (#2212) - #2222

Merged
xuyushun441-sys merged 2 commits into
mainfrom
fix/2212-finddata-pagination
Jun 23, 2026
Merged

fix(objectql): findData 返回真实 total/hasMore (#2212)#2222
xuyushun441-sys merged 2 commits into
mainfrom
fix/2212-finddata-pagination

Conversation

@baozhoutao

Copy link
Copy Markdown
Contributor

Closes#2212

问题

ObjectStackProtocolImplementation.findData 返回的分页元数据是占位值:

  • total 永远等于本页记录数,而非匹配总数
  • hasMore 恒为 false

因此前端表格认为结果集永远只有一页,永远不会请求第一批之后的记录(例如第 51 条及以后无法翻到)。REST 路由 /api/v1/data/:object 直接把该结果原样返回给前端,问题就此暴露。

修复

packages/objectql/src/protocol.tsfindData:

  • 普通查询:当带 limit 时,响应是单页,records.length 是页大小而非总数。对相同的 where 跑一次 engine.count() 得到真实 total,并由 offset + 本页长度 < total 推导 hasMore,实现真正的服务端分页。engine.count() 只认 where,无法复现 search/distinct,这类查询退化为页内估计(满页即可能有更多)而非给出错误总数。不带 limit 时返回全量,长度即总数。
  • 聚合/分组分支:原先 slice 到 limit 却把 slice 后的长度当 total、hasMore=false。改为以完整分组数为 total,hasMore 取决于 slice 是否丢弃了分组。

测试

packages/objectql/src/protocol-data.test.ts 新增 5 个分页用例,39/39 全部通过

真机验证(天顺 EHR,同一 3125 行对象)

$skip修复前修复后
0total=50, hasMore=false50 行, total=3125, hasMore=true
100total=50, hasMore=false50 行(#101–150), total=3125, hasMore=true
310025 行, total=3125, hasMore=false
31250 行, total=3125, hasMore=false

前端配套改动见 objectui 仓库 PR(ObjectGrid 服务端分页 + DataTable manual pagination)。

findData previously returned stub pagination metadata — `total` equal to
the current page's record count and `hasMore` hard-coded to false. The
frontend grid therefore believed every result set fit on a single page and
never requested records beyond the first batch (e.g. row #51+ unreachable).
When a `limit` is present the response is one page, so `records.length` is
the page size, not the match total. Run engine.count() over the same `where`
to report the true total and derive `hasMore` from offset + page vs total.
engine.count() only honors `where`, so for `search`/`distinct` queries (which
it can't reproduce) fall back to a page-local estimate instead of a wrong
total. Without a limit the full set is returned, so its length is the total.
The aggregation/grouped branch had the same bug: it sliced to `limit` but
reported the sliced length as the total with hasMore=false. It now reports
the full grouped count as total and hasMore from whether the slice dropped
any groups.
Adds 5 pagination tests to protocol-data.test.ts (39/39 pass).
@vercel

vercelBot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
specReadyReadyPreview, CommentJun 23, 2026 1:45am

Request Review

@github-actions

github-actionsBot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/objectql.

14 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/concepts/core/services.mdx(via @objectstack/objectql)
  • content/docs/concepts/implementation-status.mdx(via @objectstack/objectql)
  • content/docs/concepts/metadata-lifecycle.mdx(via @objectstack/objectql)
  • content/docs/concepts/packages.mdx(via @objectstack/objectql)
  • content/docs/guides/authentication.mdx(via @objectstack/objectql)
  • content/docs/guides/deployment-vercel.mdx(via @objectstack/objectql)
  • content/docs/guides/formula.mdx(via packages/objectql)
  • content/docs/guides/kernel-services.mdx(via @objectstack/objectql)
  • content/docs/guides/objectql-migration.mdx(via @objectstack/objectql)
  • content/docs/guides/packages.mdx(via @objectstack/objectql)
  • content/docs/guides/plugins.mdx(via @objectstack/objectql)
  • content/docs/protocol/objectos/index.mdx(via @objectstack/objectql)
  • content/docs/protocol/objectql/state-machine.mdx(via @objectstack/objectql)
  • content/docs/releases/v9.mdx(via @objectstack/objectql)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

@baozhoutao

Copy link
Copy Markdown
ContributorAuthor

前端配套 PR:objectstack-ai/objectui#1913(ObjectGrid 服务端分页 + DataTable manual pagination)。两者需配套合并。

)
Closes the missing-changeset CI gate; @objectstack/objectql user-facing fix.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation tooling labels Jun 23, 2026
@xuyushun441-sys
xuyushun441-sys merged commit 211425e into mainJun 23, 2026
16 checks passed
@xuyushun441-sys
xuyushun441-sys deleted the fix/2212-finddata-pagination branch June 23, 2026 04:12
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationImprovements or additions to documentationsize/mteststooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findData 列表分页失效:total 永远等于本页条数、hasMore 恒为 false

3 participants

@baozhoutao@xuyushun441-sys@os-zhuang