Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix n+1 query problem with event.series.title #1314

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

LukasKalbertodt
Copy link
Member

At some point, videolist blocks started requesting the events series title (which in case of the playlist block, is shown in list view). But that causes one query per event in each video block. This is a problem in particular for pages with lots of videolist blocks with lots of videos.

The solution for this is that each time an event is loaded from DB, the series title and opencast ID is also loaded. If its not used, it's just a tiny waste of DB performance, but if the GraphQL request requests it, we can immediately use it. This uses the look-ahead feature of Juniper.

I'm not a huge fan of this solution as it only fixes this one thing and does not present a general solution. However, a general solution for "execute the fewest and smartest DB queries for a GQL request" is super hard if not impossible. So I still think this should be merged, even if it adds complexity for now.

I disabled the impl_from_db block and went through all error messages to find places where events are loaded from the DB. I am pretty sure that's everything I needed to change.

At some point, videolist blocks started requesting the events series
title (which in case of the playlist block, is shown in list view). But
that causes one query per event in each video block. This is a problem
in particular for pages with lots of videolist blocks with lots of
videos.

The solution for this is that each time an event is loaded from DB, the
series title and opencast ID is also loaded. If its not used, it's just
a tiny waste of DB performance, but if the GraphQL request requests it,
we can immediately use it. This uses the look-ahead feature of Juniper.

I'm not a huge fan of this solution as it only fixes this one thing
and does not present a general solution. However, a general solution
for "execute the fewest and smartest DB queries for a GQL request" is
super hard if not impossible. So I still think this should be merged,
even if it adds complexity for now.

I disabled the `impl_from_db` block and went through all error messages
to find places where events are loaded from the DB. I am pretty sure
that's everything I needed to change.
@LukasKalbertodt LukasKalbertodt added this to the v3.0 milestone Jan 15, 2025
@github-actions github-actions bot temporarily deployed to test-deployment-pr1314 January 15, 2025 20:20 Destroyed
Copy link
Member

@owi92 owi92 left a comment

Choose a reason for hiding this comment

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

Code seems reasonable, didn't find any issues when testing.

@owi92 owi92 merged commit da131cb into elan-ev:next Jan 17, 2025
4 checks passed
@LukasKalbertodt LukasKalbertodt deleted the fix-n+1-query-problem branch January 17, 2025 12:58
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.

2 participants