Skip to content

Serialize changemaker proposals in a single pass - #2493

Merged
slifty merged 1 commit into
mainfrom
2492-changemaker-proposal-n-plus-1
Jul 2, 2026
Merged

slifty merged 1 commit into
mainfrom
2492-changemaker-proposal-n-plus-1

Conversation

@slifty

@slifty slifty commented Jul 2, 2026

Copy link
Copy Markdown
Member

This PR applies our new collection patterns (to remove N+1 queries) to the GET /changemakersProposals endpoint.

Resolves #2492

@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

🔎 A preview deployment of this pull request is available at https://utilities.philanthropydatacommons.org/pdc-service-preview-2493-lvdq9/ (and upstream https://pdc-service-preview-2493-lvdq9.ondigitalocean.app) assuming this PR is still open. 🔍

@codecov

codecov Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.73%. Comparing base (b6ece48) to head (ab48eb1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2493   +/-   ##
=======================================
  Coverage   93.73%   93.73%           
=======================================
  Files         312      312           
  Lines        3929     3929           
  Branches      532      510   -22     
=======================================
  Hits         3683     3683           
  Misses        245      245           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@slifty
slifty requested review from bickelj and hminsky2002 July 2, 2026 01:37
@slifty
slifty force-pushed the 2492-changemaker-proposal-n-plus-1 branch from 587cb1f to 0d36ac2 Compare July 2, 2026 15:01
'proposal', proposal,
'createdAt', changemaker_proposal.created_at
);
$$ LANGUAGE sql IMMUTABLE;

@bickelj bickelj Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that postgresql has this capability (marking it IMMUTABLE).

auth_context_is_administrator boolean DEFAULT FALSE
) RETURNS TABLE (id int, object jsonb) AS $$
WITH input_entries AS (
SELECT cp.*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a moment I thought "star: BAAAD, columns GOOOD" but that oversimplifies. Here we are building an intermediate result so it's OK. The higher abstraction function will filter.

:changemakerId,
:proposalId
)
RETURNING *

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I had an internal knee-jerk reaction to * here but I think our pattern is to actually want all of them.

@bickelj bickelj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is a smaller version of the previous similar changes, I did not dive so deep as to carefully understand each and every line, instead I'm leaning on our automated test passage and noticing that there were no changes to tests here.

I did some curl calls against the endpoint in demo vs the preview environment here and the preview here won in both absolute times and in consistency.

changemaker_proposal_to_json becomes a pure shape over an entry's
already-serialized changemaker and proposal.
build_changemakers_proposals_results gathers a whole page's changemakers
and proposals in one call each to build_changemakers_results /
build_proposals_results, replacing the per-row pair of builder calls the
row-by-row serializer ran.

The builder is volatile rather than STABLE: an entry embeds its proposal,
which lists its changemakers from changemakers_proposals, so the insert
path needs a fresh snapshot to see the row it just inserted.

Issue #2492 Address GET /changemakerProposals slowness
Issue #2475 Reconsider N+1 query approach for deep entities
@slifty
slifty force-pushed the 2492-changemaker-proposal-n-plus-1 branch from 0d36ac2 to ab48eb1 Compare July 2, 2026 15:31
@slifty
slifty enabled auto-merge July 2, 2026 15:31
@slifty
slifty merged commit 27f8e97 into main Jul 2, 2026
21 checks passed
@slifty
slifty deleted the 2492-changemaker-proposal-n-plus-1 branch July 2, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Address GET /changemakerProposals slowness

2 participants