=== AFTER: the two bounded queries (what the page does now) ===
projects_for(principal)          [DISTINCT, indexed]    0.16s   rows=9
rows_for('fleet-ci', principal)  [bounded fields + LIMIT]    0.13s   rows=1

=== BEFORE: the shape the page shipped first (whole document) ===
(skipped: _get_board needs a Django request; measured earlier through the
 page ITSELF as 72.7s cold / 32.7s warm on the same store)

=== QUERY PLAN ===
--- projects: SELECT DISTINCT project FROM tasks WHERE project IS NOT NULL AND project <> '' AND COALESCE(is_deleted, false) = false AND ( created_by = ? OR assignee = ? OR agent = ? ) ORDER BY project
    Unique  (cost=1301.50..1301.87 rows=50 width=16) (actual time=12.583..12.595 rows=9.00 loops=1)
      Buffers: shared hit=1142
      ->  Sort  (cost=1301.50..1301.68 rows=74 width=16) (actual time=12.580..12.583 rows=27.00 loops=1)
            Sort Key: project
            Sort Method: quicksort  Memory: 25kB
            Buffers: shared hit=1142
            ->  Seq Scan on tasks  (cost=0.00..1299.20 rows=74 width=16) (actual time=0.134..12.522 rows=27.00 loops=1)
                  Filter: ((project IS NOT NULL) AND (NOT COALESCE(is_deleted, false)) AND (project <> ''::text) AND ((created_by = 'operator'::text) OR (assignee = 'operator'::text) OR (agent = 'operator'::text)))
                  Rows Removed by Filter: 7826
                  Buffers: shared hit=1139
    Planning:
      Buffers: shared hit=210
    Planning Time: 0.701 ms
    Execution Time: 12.623 ms

--- rows: SELECT id, title, status, project, assignee, agent, created_by, priority FROM tasks WHERE project = ? AND COALESCE(is_deleted, false) = false AND ( created_by = ? OR assignee = ? OR agent = ? ) ORDER BY priority NULLS LAST, updated_at DESC NULLS LAST, id LIMIT ?
    Limit  (cost=27.15..27.16 rows=1 width=265) (actual time=0.070..0.071 rows=1.00 loops=1)
      Buffers: shared hit=11
      ->  Sort  (cost=27.15..27.16 rows=1 width=265) (actual time=0.069..0.069 rows=1.00 loops=1)
            Sort Key: priority, updated_at DESC NULLS LAST, id
            Sort Method: quicksort  Memory: 25kB
            Buffers: shared hit=11
            ->  Bitmap Heap Scan on tasks  (cost=4.33..27.14 rows=1 width=265) (actual time=0.045..0.045 rows=1.00 loops=1)
                  Recheck Cond: (project = 'fleet-ci'::text)
                  Filter: ((NOT COALESCE(is_deleted, false)) AND ((created_by = 'operator'::text) OR (assignee = 'operator'::text) OR (agent = 'operator'::text)))
                  Rows Removed by Filter: 5
                  Heap Blocks: exact=6
                  Buffers: shared hit=8
                  ->  Bitmap Index Scan on idx_tasks_project  (cost=0.00..4.33 rows=6 width=0) (actual time=0.021..0.021 rows=6.00 loops=1)
                        Index Cond: (project = 'fleet-ci'::text)
                        Index Searches: 1
                        Buffers: shared hit=2
    Planning:
      Buffers: shared hit=40
    Planning Time: 0.325 ms
    Execution Time: 0.106 ms

AFTER total (both queries, best of 3): 0.29s
# RE-MEASURED at ddb5578b
projects_for(principal)             [DISTINCT, indexed]    0.36s   result=9
rows_for('fleet-ci', principal)   [bounded + LIMIT + OFFSET]    0.31s   result=1
count_for('fleet-ci', principal)  [COUNT, the real total]    0.46s   result=1
three queries together, best of 3: 1.13s

--- projects: SELECT DISTINCT project FROM tasks WHERE project IS NOT NULL AND project <> '' AND COALESCE(is_deleted, false) = false AND ( created_by = ? OR assignee = ? OR agent = ? ) ORDER BY project
    Unique  (cost=1306.04..1306.40 rows=49 width=16) (actual time=11.672..11.683 rows=9.00 loops=1)
      Buffers: shared hit=1149
      ->  Sort  (cost=1306.04..1306.22 rows=72 width=16) (actual time=11.670..11.673 rows=27.00 loops=1)
            Sort Key: project
            Sort Method: quicksort  Memory: 25kB
            Buffers: shared hit=1149
            ->  Seq Scan on tasks  (cost=0.00..1303.82 rows=72 width=16) (actual time=0.128..11.606 rows=27.00 loops=1)
                  Filter: ((project IS NOT NULL) AND (NOT COALESCE(is_deleted, false)) AND (project <> ''::text) AND ((created_by = 'operator'::text) OR (assignee = 'operator'::text) OR (agent = 'operator'::text)))
                  Rows Removed by Filter: 7850
                  Buffers: shared hit=1146
    Planning:
      Buffers: shared hit=210
    Planning Time: 0.721 ms
    Execution Time: 11.710 ms

--- rows(limit, offset): SELECT id, title, status, project, assignee, agent, created_by, priority FROM tasks WHERE project = ? AND COALESCE(is_deleted, false) = false AND ( created_by = ? OR assignee = ? OR agent = ? ) ORDER BY priority NULLS LAST, updated_at DESC NULLS LAST, id LIMIT ? OFFSET ?
    Limit  (cost=27.16..27.16 rows=1 width=264) (actual time=0.091..0.092 rows=1.00 loops=1)
      Buffers: shared hit=11
      ->  Sort  (cost=27.16..27.16 rows=1 width=264) (actual time=0.089..0.090 rows=1.00 loops=1)
            Sort Key: priority, updated_at DESC NULLS LAST, id
            Sort Method: quicksort  Memory: 25kB
            Buffers: shared hit=11
            ->  Bitmap Heap Scan on tasks  (cost=4.33..27.15 rows=1 width=264) (actual time=0.062..0.063 rows=1.00 loops=1)
                  Recheck Cond: (project = 'fleet-ci'::text)
                  Filter: ((NOT COALESCE(is_deleted, false)) AND ((created_by = 'operator'::text) OR (assignee = 'operator'::text) OR (agent = 'operator'::text)))
                  Rows Removed by Filter: 5
                  Heap Blocks: exact=6
                  Buffers: shared hit=8
                  ->  Bitmap Index Scan on idx_tasks_project  (cost=0.00..4.33 rows=6 width=0) (actual time=0.038..0.038 rows=6.00 loops=1)
                        Index Cond: (project = 'fleet-ci'::text)
                        Index Searches: 1
                        Buffers: shared hit=2
    Planning:
      Buffers: shared hit=40
    Planning Time: 0.326 ms
    Execution Time: 0.121 ms

--- count: SELECT COUNT(*) FROM tasks WHERE project = ? AND COALESCE(is_deleted, false) = false AND ( created_by = ? OR assignee = ? OR agent = ? )
    Aggregate  (cost=27.15..27.16 rows=1 width=8) (actual time=0.041..0.042 rows=1.00 loops=1)
      Buffers: shared hit=8
      ->  Bitmap Heap Scan on tasks  (cost=4.33..27.15 rows=1 width=0) (actual time=0.035..0.036 rows=1.00 loops=1)
            Recheck Cond: (project = 'fleet-ci'::text)
            Filter: ((NOT COALESCE(is_deleted, false)) AND ((created_by = 'operator'::text) OR (assignee = 'operator'::text) OR (agent = 'operator'::text)))
            Rows Removed by Filter: 5
            Heap Blocks: exact=6
            Buffers: shared hit=8
            ->  Bitmap Index Scan on idx_tasks_project  (cost=0.00..4.33 rows=6 width=0) (actual time=0.012..0.013 rows=6.00 loops=1)
                  Index Cond: (project = 'fleet-ci'::text)
                  Index Searches: 1
                  Buffers: shared hit=2
    Planning:
      Buffers: shared hit=6
    Planning Time: 0.186 ms
    Execution Time: 0.071 ms

