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

PCR optimize instructor's course query #504

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AaDalal
Copy link
Contributor

@AaDalal AaDalal commented Aug 23, 2023

NOTE: this is not currently working! This is a useful baseline but it is only a starting point as there is still debugging to be done.
Use the USE_NEW_QUERIES toggle in review.views to switch between using the new (not working) queries and the old (working but slow) queries. After you flip this toggle you can run the server and visit a URL like http://127.0.0.1:8000/api/review/instructor/14021 to see what the new and old queries return, respectively.

This PR aims to optimize the query (in postgres) that aggregates reviews for an instructor's courses.

@AaDalal AaDalal marked this pull request as draft August 23, 2023 07:08
@@ -372,6 +373,8 @@ def check_instructor_id(instructor_id):
"difficulty",
]

# TODO: remove before merging into prod
Copy link
Member

Choose a reason for hiding this comment

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

Commenting here as reminder

@@ -446,6 +490,7 @@ def instructor_reviews(request, instructor_id):
courses_res = dict()
max_sem = dict()
for r in courses.values():
print(r)
Copy link
Member

Choose a reason for hiding this comment

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

rm

@rohangpta
Copy link
Member

Is the idea behind this PR to remove some of the python logic that gets max sem and port over to SQL?

Why do we see these performance issues to begin with? We are caching pages for 1 month as per backend/review/urls.py and requests after that should be quite free. Should we try to also warm the cache somehow?

Have you spoken to your friend about scraping our data? I worry we're seeing some interference here

@AaDalal
Copy link
Contributor Author

AaDalal commented Sep 4, 2023

Is the idea behind this PR to remove some of the python logic that gets max sem and port over to SQL?

Why do we see these performance issues to begin with? We are caching pages for 1 month as per backend/review/urls.py and requests after that should be quite free. Should we try to also warm the cache somehow?

Have you spoken to your friend about scraping our data? I worry we're seeing some interference here

Yeah -- he's not doing any scraping

@AaDalal
Copy link
Contributor Author

AaDalal commented Sep 4, 2023

Is the idea behind this PR to remove some of the python logic that gets max sem and port over to SQL?

Why do we see these performance issues to begin with? We are caching pages for 1 month as per backend/review/urls.py and requests after that should be quite free. Should we try to also warm the cache somehow?

Have you spoken to your friend about scraping our data? I worry we're seeing some interference here

Not it's changing the output query logic (e.g., you can try flipping the toggle and looking at the generated SQL queries. The ones output by the current query logic are really complex, and these ones are faster to execute by the postgres query engine.

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.

2 participants