mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
fix(agent): use type index for compaction discovery
This commit is contained in:
parent
374c5b6dd0
commit
eb2683fc59
1 changed files with 9 additions and 5 deletions
|
|
@ -46,15 +46,19 @@ export async function readCachedEntryRowsByType(
|
|||
branch: CachedBranch,
|
||||
type: SessionEntryRow["type"],
|
||||
): Promise<SessionEntryRow[]> {
|
||||
// Drive the join from the usually sparse entry type. Ordering from branch_entries
|
||||
// makes SQLite scan the complete cached path before filtering by type.
|
||||
return db
|
||||
.prepare(
|
||||
`SELECT e.session_id, e.id, e.entry_seq, e.parent_id, e.type, e.timestamp, e.payload
|
||||
FROM branch_entries AS b
|
||||
JOIN session_entries AS e ON e.session_id = b.session_id AND e.id = b.entry_id
|
||||
WHERE b.session_id = ? AND b.branch_id = ? AND b.entry_seq <= ? AND e.type = ?
|
||||
ORDER BY b.entry_seq DESC`,
|
||||
FROM session_entries AS e INDEXED BY idx_session_entries_session_type
|
||||
CROSS JOIN branch_entries AS b
|
||||
WHERE e.session_id = ? AND e.type = ?
|
||||
AND b.session_id = e.session_id AND b.entry_id = e.id
|
||||
AND b.branch_id = ? AND b.entry_seq <= ?
|
||||
ORDER BY e.entry_seq DESC`,
|
||||
)
|
||||
.all<SessionEntryRow>(sessionId, branch.branchId, branch.leafSeq, type);
|
||||
.all<SessionEntryRow>(sessionId, type, branch.branchId, branch.leafSeq);
|
||||
}
|
||||
|
||||
export async function readCachedEntrySeq(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue