ship 1.4.51:Arcrun@86fc731f375d

This commit is contained in:
ship
2026-08-24 18:23:34 +08:00
parent 4324bba8b7
commit a925e2d7dd
11 changed files with 527 additions and 169 deletions
+14 -6
View File
@@ -3491,11 +3491,19 @@ async function getRecord(db, recordId) {
const identity = await db.prepare("SELECT owner_id FROM entries WHERE id = ?").bind(recordId).first();
return { record_id: recordId, template_id: belongs.dst_id, values, owner_id: identity?.owner_id ?? null };
}
async function searchByTemplate(db, template, owner_id, limit = 100, offset = 0) {
async function searchByTemplatePage(db, template, owner_id, limit = 100, offset = 0) {
const tpl = await getTemplate(db, template);
if (!tpl) return [];
if (!tpl) return { records: [], total: 0 };
const cap = Math.min(Math.max(limit, 1), 500);
const skip = Math.max(offset, 0);
const totalRow = owner_id ? await db.prepare(
// kbdb-sql-ok:牆內本體(kbdb/src/actions/
`SELECT COUNT(*) AS total FROM entries WHERE rel_id = '${SYS_BELONGS}' AND dst_id = ? AND owner_id = ?`
).bind(tpl.id, owner_id).first() : await db.prepare(
// kbdb-sql-ok:同上
`SELECT COUNT(*) AS total FROM entries WHERE rel_id = '${SYS_BELONGS}' AND dst_id = ?`
).bind(tpl.id).first();
const total = totalRow?.total ?? 0;
const res = owner_id ? await db.prepare(
// kbdb-sql-ok:牆內本體(kbdb/src/actions/);本次 checkout 開在 worktree /private/tmp/wt-graph-first-44/hook 逐字比對 matrix/arcrun/kbdb/src/ 吃不到,與 962d8635919c6b 記載的是同一個假警報
`SELECT src_id AS record_id FROM entries
@@ -3508,7 +3516,7 @@ async function searchByTemplate(db, template, owner_id, limit = 100, offset = 0)
ORDER BY created_at DESC, rowid DESC LIMIT ? OFFSET ?`
).bind(tpl.id, cap, skip).all();
const ids = (res.results ?? []).map((r) => r.record_id);
if (ids.length === 0) return [];
if (ids.length === 0) return { records: [], total };
const byId = /* @__PURE__ */ new Map();
for (const id of ids) byId.set(id, { record_id: id, template_id: tpl.id, values: {}, owner_id: null });
for (let i = 0; i < ids.length; i += 90) {
@@ -3533,7 +3541,7 @@ async function searchByTemplate(db, template, owner_id, limit = 100, offset = 0)
if (rec) rec.owner_id = r.owner_id;
}
}
return ids.map((id) => byId.get(id)).filter((r) => !!r);
return { records: ids.map((id) => byId.get(id)).filter((r) => !!r), total };
}
async function deleteRecord(db, recordId) {
const belongs = await recordBelongs(db, recordId);
@@ -4113,14 +4121,14 @@ var intParam = (raw2, fallback, min, max) => {
recordRoutes.get("/by-template/:template", async (c) => {
const limit = intParam(c.req.query("limit"), 100, 1, 500);
const offset = intParam(c.req.query("offset"), 0, 0, Number.MAX_SAFE_INTEGER);
const records = await searchByTemplate(
const { records, total } = await searchByTemplatePage(
c.env.DB,
c.req.param("template"),
c.req.query("owner_id") || void 0,
limit,
offset
);
return c.json({ success: true, records, count: records.length, limit, offset });
return c.json({ success: true, records, count: records.length, limit, offset, total });
});
recordRoutes.get("/:recordId", async (c) => {
const rec = await getRecord(c.env.DB, c.req.param("recordId"));