External approver approvals list under "My account" does not load

Description

Problem

An external approver who is logged in on app.approval-path.com and clicks "My account" is taken to their approvals list (tabs Awaiting, Queued, History). The page keeps loading: no response arrives even after 3 minutes and the browser gives up. The approver cannot see their approvals or make a decision from there.

Affects Approval Path in production. Every attempt to open the page keeps the database busy for minutes, so many attempts at once can slow down the whole application.

Cause

When looking up a given approver's approvals, the database first goes through all approvals in the system (hundreds of thousands). For each one it checks whether it is archived, deleted or outdated, and only at the end filters by the approver's email address. Load time therefore grows with the total number of approvals in the system, not with the number of approvals of this approver. The same queries already had a similar problem in November 2025.

Two things in the list and counter queries made the database choose that order:

  1. Archived, deleted and outdated approvals were hidden by checking for an empty date on joined tables. PostgreSQL misjudges such a check and expects about 1 matching approval, so it never starts from the approver's email.

  2. The check "the approval has not failed" was placed inside the email lookup. Because of that, the database had to run it for every approval step in the system before looking at the email.

Diagnostics (production)

  • Caddy logs: GET /dashboard.html for a logged-in user takes 13-190 s and ends without a status because the client gives up. /login.html redirects a logged-in user (302) to /dashboard.html. Login and /settings.html respond in ~50 ms.

  • Application logs (ap): no errors or timeouts for the dashboard. The dashboard queries have no timeout set.

  • pg_stat_activity while the page is loading:

    • one active query starting with select "public"."approval_config"."config_id", ..., i.e. the list from ApprovalPathDao.listEmailApprovals;

    • it runs in parallel: leader plus 2 workers (IPC / MessageQueueSend);

    • pg_blocking_pids is empty, so there are no locks.

  • EXPLAIN of the list query (status IN_PROGRESS, ORDER BY approval.created_at DESC LIMIT 20):

    • the plan starts with Parallel Seq Scan on approval (~430k rows) joined with approval_config;

    • after LEFT JOIN approval_path_outdated with the filter changed_date IS NULL the planner estimates rows=1, while ~250k rows actually remain;

    • because of that everything above is nested loops, including Seq Scan on approval_path_archived (~19.5k rows) with a Join Filter, executed for every row;

    • the email filter (idx_approval_email_step_lower_email) is applied only at the very top of the plan, as the last Semi Join.

  • Indexes: idx_approval_path_archived_approval_id exists and is valid (indisvalid = true), yet the planner does not use it.

  • Table statistics (pg_stat_user_tables): approval 438k rows, approval_config 615k, approval_step 2.04M (371k dead), approval_email_step 8.3k. Last autoanalyze runs were between 11.11 and 24.11, so the statistics are not badly outdated.

  • How to check: open "My account" as a logged-in approver and while it loads run:

SELECT pid, now() - query_start AS dur, state, wait_event_type, wait_event,       pg_blocking_pids(pid) AS blocked_by, queryFROM pg_stat_activityWHERE datname = current_database() AND pid <> pg_backend_pid() AND state <> 'idle'ORDER BY dur DESC;

Steps to reproduce

  1. Log in as an external approver on app.approval-path.com (production).

  2. On the home page click "My account".

The problem may not occur on a test site, as it depends on the number of approvals in the database.

Actual behavior

After the redirect to the approvals list the page keeps loading and never shows the list.

Expected behavior

The approvals list and the tab counters load within a few seconds, regardless of the number of approvals in the whole system.

Acceptance criteria

  • In production, a logged-in external approver who clicks "My account" sees the approvals list in under 2 seconds.

  • The Awaiting, Queued and History tabs and their counters load just as fast.

  • Moving between list pages (next, previous) loads just as fast.

  • The lists and counters show the same approvals as before the change: archived, deleted, outdated and past-decision-deadline approvals stay hidden.

  • An approver with a large number of approvals (hundreds) also sees the list within that time.

Change

  • The approvals list, its page count and the three tab counters now start from the approver's email steps and only then check the rest, so load time depends on the approver's own approvals, not on all approvals in the system.

  • Archived, deleted and outdated approvals are hidden with the same checks the other approval lists already use.

  • The "has the approval failed" check runs on the approver's approvals only.

  • Measured on generated data of production size (440k approvals, 2.1M steps, 9k email steps, one approver with 437 approvals): before 2-22 s per query, after 4-90 ms. Lists, page counts and counters return exactly the same approvals as before for every tab.

Decisions

  • No database change: the existing email index is enough once the queries start from it.

Manual tester notes

  1. Log in as an external approver on the QA external approver page (an email address that has approvals in several states: awaiting, queued, approved or rejected).

  2. Click "My account".

  3. Check that the list loads within a couple of seconds and that the Awaiting, Queued and History tabs show the same approvals and counters as on production for a comparable approver: awaiting decisions under Awaiting, later steps under Queued, decided or rejected approvals under History.

  4. Archive one of the approver's approvals in Jira or Confluence, reload "My account": it disappears from the list and the counters drop by one.

  5. If the approver has more than one page, move to the next page and back: each page loads just as fast.

Before release

  • After the deploy, open "My account" as an external approver on production and check that the list loads in under 2 seconds.