Skip to content

Conversation

@rhysyngsun
Copy link
Contributor

@rhysyngsun rhysyngsun commented Jul 10, 2024

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/4828

Description (What does it do?)

This addresses a performance issue created by N+1 query issues due to a hardcoded query in the serializer. I took the approach of leaving in the existing code as a fallback but otherwise annotating the query for better performance. I also put in place a query count assertion on testing this API

I saw performance improve at least an order of magnitude and it'll probably run better in deployed environments:

Before:
Screenshot 2024-07-10 at 16-23-21 Silky - Requests
After:
Screenshot 2024-07-11 at 13-08-36 Silky - Requests

How can this be tested?

  • Hit the /api/v1/topics/ api on the main branch and observe that it's slow (seconds).
  • Hit the same API on this branch and it should be much faster (milliseconds).
  • You should be able to go to /silk and it requires you to be a logged in superuser to access.

@rhysyngsun rhysyngsun added the Needs Review An open Pull Request that is ready for review label Jul 10, 2024
@rhysyngsun rhysyngsun force-pushed the nl/topics-api-performance branch 3 times, most recently from eabb23c to 85b3c3c Compare July 11, 2024 15:23
@rhysyngsun rhysyngsun force-pushed the nl/topics-api-performance branch from 85b3c3c to 24b92fe Compare July 11, 2024 15:59
@gumaerc gumaerc self-assigned this Jul 11, 2024
Copy link
Contributor

@gumaerc gumaerc left a comment

Choose a reason for hiding this comment

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

👍 LGTM

Since django-silk isn't installed on main, I did some basic profiling using the network tab in Chrome inspector. On main I was seeing response times up to and over 1 second, and on this branch I saw response times on the order of ~100ms for the topics endpoint.

image

@rhysyngsun rhysyngsun merged commit f1fab68 into main Jul 11, 2024
@rhysyngsun rhysyngsun deleted the nl/topics-api-performance branch July 11, 2024 19:38
@odlbot odlbot mentioned this pull request Jul 11, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants