-
Notifications
You must be signed in to change notification settings - Fork 214
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
Simplify report views #1872
Simplify report views #1872
Conversation
d5d9a38
to
2944aae
Compare
@krysal limit 21 is a default for queries made by Django, I came across this while debugging that perf issue last month! |
It seemed like that. Thank you, Zack! Found a reference here: |
2944aae
to
eb49dcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests great and the changes look good to me!
Thanks for the excellent testing instructions. I tried making a report on main
and saw three SELECTs, an INSERT, and an UPDATE. On the branch I saw that one of the SELECTs and the redundant UPDATE were both eliminated. LGTM!
|
||
serializer = self.get_serializer(report) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what was going on in the original code here 🤔 But the changes look good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be the original author assumed that the serializer's data wouldn't be updated if the underlying object changed during save
? The only reason I could think of for this is if one of the fields on the response was something that could be changed by saving, but none are:
fields = ["identifier", "reason", "description"] |
Anyway, that's just a guess. I'm not sure what Django's behaviour is when saving the serializer changes the underlying data (due to the model's save
method making changes), but in this case it definitely does not appear to matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
|
||
# Prevent redundant update statement when creating the report | ||
if self.status != PENDING: | ||
same_reports.update(status=self.status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this would be clearer if the status check was before the query on line 238 and caused an early return? Something like:
if self.status == PENDING:
return
Only because then it is quite clear that the intention is that pending reports should have no effect on other reports.
|
||
serializer = self.get_serializer(report) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be the original author assumed that the serializer's data wouldn't be updated if the underlying object changed during save
? The only reason I could think of for this is if one of the fields on the response was something that could be changed by saving, but none are:
fields = ["identifier", "reason", "description"] |
Anyway, that's just a guess. I'm not sure what Django's behaviour is when saving the serializer changes the underlying data (due to the model's save
method making changes), but in this case it definitely does not appear to matter.
@krysal I'm merging this to test the DAG sync script fix. I'll test this in staging to confirm things are working as expected after it deploys 👍 |
Fixes
Fixes #1037 by @obulat
Description
Pass the media identifier directly instead of using the method serializer. This update saves two db statements per report. One query and one update were both redundant.
Testing Instructions
just api/recreate
DJANGO_DB_LOGGING=True
on your .env fileChecklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin