Skip to content

fix(panel): 记忆面板的「共 N 条」与分类 chip 改读服务端真分布(#597) - #630

Open
modusensus wants to merge 1 commit into
mainfrom
fix/597-panel-counts
Open

modusensus wants to merge 1 commit into
mainfrom
fix/597-panel-counts

Conversation

@modusensus

Copy link
Copy Markdown
Member

背景

#597(报告人给了完整对照表与建议修法,评论区复核补全了因果链):记忆面板的数字全部读错——

  1. **页头「共 N 条」**用 visible.length(已加载页行数):滚动一次后恒停在 200,库 2551 条也显示 200;
  2. 分类栏塌陷:浏览页的查询串带着选中的 type(client.js 的 filterQS),所以已加载行里只剩当前类——chips 从页内现数后其它类计数为 0,被 EXPLORER_TYPES.filter((k) => counts[k]) 整条滤掉,分类栏塌剩「全部 + 当前类」,数字还会从 5 跳到 200。

服务端的 total 一直是对的(与行同口径),页面的「加载更多」按钮早就在用它——只是页头和分类栏没用。只改前端做不到:前端手上没有其它类的数字。

改动

服务端(两张 HTTP 面同口径,只许剩鉴权与路径不同):

  • store.count() 的 WHERE 构造抽成共用 pushCountFilters(type 刻意不在其中——count 按调用方带、countByType 刻意不带);count() 签名与行为不变;
  • 新增 store.countByType(opts):同一份筛选、不带 type,一次 GROUP BY type 拿全库分布;
  • 宿主内 /api/dsh-mneme/list 与 Bearer /memories 答复补 typeCounts 格(与 total 完全同一份筛选参数);按 id 取单条的答复不带这一格——分布无意义,客户端据此降级。

客户端(lib/client.js):

  • 页头 = 服务端 total(搜索态的 total 本就是命中数,语义不变;browse 态不再用 visible.length);
  • 分类 chips = typeCounts 全库分布、缺类补 0——选中一类后分类栏恒定不塌;
  • 「全部」chip = 分布合计(不再从 5 跳到 200);
  • 降级回退:老服务端没有 typeCounts 时退回页内现数——功能不炸,只是回到旧的「只数已加载页」行为。

验证

  • test/store.test.js +1:分布合计恒等于 count(undefined)、带 minImportance 筛选时同口径;
  • test/api.test.js +1 / test/standalone-api.test.js +1:带 type=project 请求下 typeCounts 仍是全量分布(其它类的数字活着的)、合计 = total;
  • test/client.test.js +1 源码断言:服务端源、降级回退、页头 total、全部 chip 合计四处同时钉住;
  • 全量 node --test test/*.test.js:3158 用例 / 3157 通过 / 0 失败 / 1 跳过;check-sync 118 一致。

不在本 PR

状态页 MemoriesStatusCard 的每类一次请求(N+1)是同一痛点的另一处,可后续切到 typeCounts(一张请求替代六张),CHANGELOG 里已留话头。

Closes #597。

浏览页被 type 筛过又分了页,页内现数两头都数不出真分布:
- 页头「共 N 条」用 visible.length(已加载页行数),滚动一次后恒停在 200;
- 分类 chip 从已加载页现数,而页的查询串带着选中的 type——选中任一类后
  其它类计数为 0 被 filter 整条滤掉,分类栏塌剩两枚、数字从 5 跳到 200。

服务端:store.count() 的 WHERE 构造抽成共用 pushCountFilters(type 刻意
不在其中),新增 countByType(opts)——同一份筛选、不带 type,一次 GROUP BY
拿全库分布;宿主内 /api/dsh-mneme/list 与 Bearer /memories 两张面同口径补
typeCounts 格(按 id 取单条的答复不带,分布无意义)。

客户端:页头 = 服务端 total(搜索态的 total 本就是命中数);chips =
typeCounts 全库分布、缺类补 0;「全部」chip = 分布合计。老服务端没有
typeCounts 时退回页内现数——功能不炸,只是回到旧的「只数已加载页」行为。

test: store.test.js +1(分布合计 = count(undefined)、筛选同口径);
api.test.js / standalone-api.test.js 各 +1(带 type 请求下分布仍全量);
client.test.js +1 源码断言(服务端源 + 降级路径同时在)。全量 3158 用例 /
3157 通过 / 0 失败 / 1 跳过;check-sync 118 一致。
Copilot AI lite review requested due to automatic review settings November 9, 2026 21:22
@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 514d238 and 534ac31.

Files selected for processing: 14

  • dsh-mneme/CHANGELOG.md
  • dsh-mneme/lib/api-standalone.js
  • dsh-mneme/lib/api.js
  • dsh-mneme/lib/client.js
  • dsh-mneme/lib/service.js
  • dsh-mneme/lib/store.js
  • dsh-mneme/src/api-standalone.js
  • dsh-mneme/src/api.js
  • dsh-mneme/src/service.js
  • dsh-mneme/src/store.js
  • dsh-mneme/test/api.test.js
  • dsh-mneme/test/client.test.js
  • dsh-mneme/test/standalone-api.test.js
  • dsh-mneme/test/store.test.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] 记忆面板的总数与分类计数只数「已加载的一页」:库 2551 条时页头恒显示 200

2 participants