Merged
Size
L
Change Breakdown
Performance40%
Refactor40%
Maintenance20%
#3309TaskRun optimizations: dropping FKs and some indexes

Postgres query fallback removed and database schema optimized for TaskRun

Removing the legacy Postgres fallback for run listings trims down the codebase and shifts reliance entirely to ClickHouse, reducing database write overhead.

A Postgres fallback path for listing task runs was previously maintained in case ClickHouse queries failed. This redundancy required heavy foreign key constraints and indexes that added write overhead to every database insert. The fallback path and its associated feature flag are removed. The system now relies entirely on ClickHouse for listing and counting runs. Overhead from Postgres operations is eliminated, speeding up inserts and updates. Hundreds of lines of obsolete fallback code are dropped. Additionally, the telemetry buffer for scheduled runs is extended to 60 seconds to ensure traces link correctly.

View Original GitHub Description

Summary

  • Drop all 8 foreign key constraints on TaskRun. The run listing path is now fully ClickHouse-backed so we no longer need Postgres to enforce referential integrity on this table. The FK constraints add write overhead on every insert/update with no remaining benefit. Prisma queries are unaffected.
  • Remove PostgresRunsRepository and its associated feature flag (runsListRepository), which was the last remaining code path querying TaskRun directly for list/count operations.
  • Drop three indexes that were only useful for the Postgres run list path and have no remaining query consumers:
    • TaskRun_runtimeEnvironmentId_id_idx — was the cursor pagination index for PostgresRunsRepository; superseded by the (runtimeEnvironmentId, createdAt DESC) composite index
    • TaskRun_scheduleId_idx — redundant with the (scheduleId, createdAt DESC) composite index; no direct Postgres queries filter by scheduleId alone
    • TaskRun_rootTaskRunId_idx — no queries filter TaskRun by rootTaskRunId as a WHERE clause anywhere in the codebase

All index drops use CONCURRENTLY IF EXISTS to avoid table locks in production.

Test plan

  • pnpm run db:migrate:deploy applies all migrations cleanly
  • pnpm run typecheck --filter webapp passes
  • Run list pages load correctly in the dashboard (ClickHouse path)
  • Scheduled task runs still trigger and appear correctly
© 2026 · via Gitpulse