Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): shell reads stop counting every turn item #27975

ClosedPyseph(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/27975/headopened View on GitHub

Showing 6 changed files with 128 additions and 14 deletions (loading 3).

x
0 of 6 viewed, 6 left
8 additions and 14 deletionsapps/server/src/orchestration-v2/ProjectionStore.tsModified
View file
@@ -6374,27 +6374,21 @@
const selectShellRunItemCounts = (threadIds: ReadonlyArray<ThreadId>) =>
sql<ShellRunItemCountRow>`
- SELECT thread_id, run_id, COUNT(*) AS item_count
- FROM orchestration_v2_projection_turn_items
- WHERE run_id IS NOT NULL AND thread_id IN (SELECT value FROM json_each(${encodeIdList(threadIds)}))
- GROUP BY thread_id, run_id
+ SELECT thread_id, run_key AS run_id, item_count
+ FROM orchestration_v2_projection_turn_item_counts
+ WHERE run_key <> '' AND thread_id IN (SELECT value FROM json_each(${encodeIdList(threadIds)}))
- // Count all selected threads in one index walk; fork sources still need per-run counts.
const selectShellItemCounts = (threadIds: ReadonlyArray<ThreadId>) =>
sql<ShellItemCountRow>`
SELECT counts.thread_id,
- SUM(CASE WHEN counts.run_id IS NULL OR r.status <> 'rolled_back'
+ SUM(CASE WHEN counts.run_key = '' OR r.status <> 'rolled_back'
THEN counts.item_count ELSE 0 END) AS item_count,
- SUM(CASE WHEN counts.run_id IS NULL THEN counts.item_count ELSE 0 END)
+ SUM(CASE WHEN counts.run_key = '' THEN counts.item_count ELSE 0 END)
AS runless_item_count
- FROM (
- SELECT thread_id, run_id, COUNT(*) AS item_count
- FROM orchestration_v2_projection_turn_items
- WHERE thread_id IN (SELECT value FROM json_each(${encodeIdList(threadIds)}))
- GROUP BY thread_id, run_id
- ) counts
- LEFT JOIN orchestration_v2_projection_runs r ON r.run_id = counts.run_id