The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as SqlClient from "effect/sql/SqlClient"; |
| 3 | |
| 4 | export default Effect.gen(function* () { |
| 5 | const sql = yield* SqlClient.SqlClient; |
| 6 | |
| 7 | // Every command reads its thread's nodes without the settled leaves. This index lets that read |
| 8 | // seek the nodes it keeps instead of fetching each finished tool call to drop it. The |
| 9 | // omitSettledLeafNodes read in ProjectionStore must spell this expression the same way. |
| 10 | yield* sql` |
| 11 | CREATE INDEX IF NOT EXISTS orchestration_v2_projection_nodes_settled_leaf_idx |
| 12 | ON orchestration_v2_projection_nodes( |
| 13 | thread_id, |
| 14 | (kind IN ('tool_call', 'assistant_message', 'reasoning') |
| 15 | AND status IN ('completed', 'interrupted', 'failed', 'cancelled', 'rolled_back') |
| 16 | AND run_id IS NOT NULL) |
| 17 | ) |
| 18 | `; |
| 19 | |
| 20 | // A dispatcher thread is the source of thousands of consumed transfers. With status in the |
| 21 | // index, a read of the pending ones no longer fetches each consumed row to check it. |
| 22 | yield* sql`DROP INDEX IF EXISTS orchestration_v2_projection_context_transfers_source_thread_idx`; |
| 23 | yield* sql` |
| 24 | CREATE INDEX IF NOT EXISTS orchestration_v2_projection_context_transfers_source_thread_status_idx |
| 25 | ON orchestration_v2_projection_context_transfers(source_thread_id, status) |
| 26 | `; |
| 27 | }); |