Skip to content

prefetch participant and voter counts in contributor index - #2714

Merged
niklasmohrin merged 4 commits into
e-valuation:mainfrom
Kakadus:prefetch-contributor-index
Aug 6, 2026
Merged

prefetch participant and voter counts in contributor index#2714
niklasmohrin merged 4 commits into
e-valuation:mainfrom
Kakadus:prefetch-contributor-index

Conversation

@Kakadus

@Kakadus Kakadus commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

relates to #1229

Directly reduces n database hits.
When testing with 200 evaluations 10 times, the accumulated test-runtime was reduced from 50s to 44s on my laptop. Even with 10 evaluations, I see a speedup (4.820s -> 3.689s).

@richardebeling richardebeling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm. Can you add a test that asserts that we have < N queries? (I would assume that, for each relation we currently prefetch_related, the test fails if we remove it).

Comment thread evap/contributor/views.py Outdated
@github-actions github-actions Bot added the Stale label Jul 7, 2026
@Kakadus
Kakadus force-pushed the prefetch-contributor-index branch from 01d64f2 to 2e3855f Compare August 4, 2026 16:00
@Kakadus

Kakadus commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

finally found some time to revisit this.

Can you add a test that asserts that we have < N queries?

No, because we do not have < N queries yet. With 100 evaluations, contributions, we have 540 queries. Without this PR, we have ~200 more. For a test, I can cut down the number if objects (say 10 each) and assert that we are not constant (currently 90 queries, so assert we make 80-100 queries). For reference, the constant PoC at #2715 has 43 queries.
That way, we see degradations and monitor the current state, although margins are quite small.

@Kakadus
Kakadus requested a review from richardebeling August 4, 2026 21:56
@Kakadus Kakadus removed the Stale label Aug 4, 2026

@richardebeling richardebeling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, thanks. The fixed contributor page (via #2715) is going to be epic.

cls.responsible = result["responsible"]
cls.test_users = [result["editor"], cls.responsible]

def test_num_queries_is_not_constant(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

haha :D

@niklasmohrin niklasmohrin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@niklasmohrin
niklasmohrin merged commit 0a5f134 into e-valuation:main Aug 6, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants