Addresses performance issues for the topics API #1250
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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:


After:
How can this be tested?
/api/v1/topics/api on themainbranch and observe that it's slow (seconds)./silkand it requires you to be a logged in superuser to access.