Sync static story thread list query
This commit is contained in:
parent
c1366facb5
commit
701ebce0d4
27
src/db.ts
27
src/db.ts
@ -516,18 +516,26 @@ export async function listStoryThreads(args: {
|
|||||||
status?: string;
|
status?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const values: unknown[] = [];
|
const limit = Math.min(Math.max(Number(args.limit ?? 30), 1), 100);
|
||||||
const where: string[] = [];
|
|
||||||
|
|
||||||
if (args.status) {
|
if (args.status) {
|
||||||
if (!STORY_STATUSES.has(args.status)) throw new Error("Invalid story status");
|
if (!STORY_STATUSES.has(args.status)) throw new Error("Invalid story status");
|
||||||
values.push(args.status);
|
const result = await pool.query(
|
||||||
where.push(`t.status=${values.length}`);
|
`SELECT t.*,
|
||||||
|
(SELECT COUNT(*)::int FROM story_nodes n WHERE n.thread_id=t.id) AS node_count,
|
||||||
|
(SELECT COUNT(*)::int FROM story_edges e WHERE e.thread_id=t.id) AS edge_count,
|
||||||
|
(SELECT result FROM story_research_checks c
|
||||||
|
WHERE c.thread_id=t.id AND c.check_type='counter_evidence'
|
||||||
|
LIMIT 1) AS counter_evidence_result
|
||||||
|
FROM story_threads t
|
||||||
|
WHERE t.status=$1
|
||||||
|
ORDER BY t.updated_at DESC
|
||||||
|
LIMIT $2`,
|
||||||
|
[args.status, limit]
|
||||||
|
);
|
||||||
|
return result.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
const limit = Math.min(Math.max(Number(args.limit ?? 30), 1), 100);
|
|
||||||
values.push(limit);
|
|
||||||
|
|
||||||
const result = await pool.query(
|
const result = await pool.query(
|
||||||
`SELECT t.*,
|
`SELECT t.*,
|
||||||
(SELECT COUNT(*)::int FROM story_nodes n WHERE n.thread_id=t.id) AS node_count,
|
(SELECT COUNT(*)::int FROM story_nodes n WHERE n.thread_id=t.id) AS node_count,
|
||||||
@ -536,10 +544,9 @@ export async function listStoryThreads(args: {
|
|||||||
WHERE c.thread_id=t.id AND c.check_type='counter_evidence'
|
WHERE c.thread_id=t.id AND c.check_type='counter_evidence'
|
||||||
LIMIT 1) AS counter_evidence_result
|
LIMIT 1) AS counter_evidence_result
|
||||||
FROM story_threads t
|
FROM story_threads t
|
||||||
${where.length ? "WHERE " + where.join(" AND ") : ""}
|
|
||||||
ORDER BY t.updated_at DESC
|
ORDER BY t.updated_at DESC
|
||||||
LIMIT ${values.length}`,
|
LIMIT $1`,
|
||||||
values
|
[limit]
|
||||||
);
|
);
|
||||||
return result.rows;
|
return result.rows;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user