[WIP] Add an is_draft property to file attachments.
Review Request #13138 — Created July 13, 2023 and discarded
Information | |
---|---|
maubin | |
Review Board | |
release-6.x | |
13142, 13135 | |
Reviewers | |
reviewboard | |
This adds an
is_draft
property to file attachments, to easily check
when a file attachment is a draft or if it's published. This also
updates areas in the code where we check if a file attachment is a
draft. And unit tests for the file attachment resources have been
updated to check all of the fields of the file attachment.
- Ran unit tests.
- Used the property in upcoming changes.
- Tested uploading user file attachments to comments, saw
nothing out of the ordinary.
Summary |
---|
Description | From | Last Updated |
---|---|---|
For a property, we just use Type, like it's an attribute. Same with the summary: It should be in more … |
|
|
self.user is the cheapest thing to check, so let's check that first. |
|
|
Missing a trailing comma. |
|
|
Missing a trailing comma. |
|
|
Missing a trailing comma. |
|
|
Missing a trailing comma. |
|
|
My concern is that this can easily lead to ballooning queries in any typical usage. Every is_draft is going to … |
|
|
There's an extra : here. |
|
|
Can you do assertQueries for all these? |
|
|
line too long (85 > 79 characters) Column: 80 Error code: E501 |
![]() |
|
at least two spaces before inline comment Column: 47 Error code: E261 |
![]() |

Change Summary:
- Added the
is_draft
property to the file attachment JS model. - Updated unit tests for file attachment resources.
Description: |
|
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Commits: |
|
||||||||||||||||||
Diff: |
Revision 2 (+190 -18) |
Checks run (2 succeeded)

Change Summary:
Posted my last version too early by accident.
Commits: |
|
||||||
---|---|---|---|---|---|---|---|
Diff: |
Revision 3 (+476 -46) |
Checks run (2 succeeded)
-
-
reviewboard/attachments/models.py (Diff revision 3) For a property, we just use
Type
, like it's an attribute.Same with the summary: It should be in more of an attribute-style summary, rather than saying it returns something.
-
reviewboard/attachments/models.py (Diff revision 3) self.user
is the cheapest thing to check, so let's check that first. -
-
-
-

Commits: |
|
||||||
---|---|---|---|---|---|---|---|
Diff: |
Revision 4 (+474 -46) |
Checks run (2 succeeded)

Change Summary:
- Defaults
isDraft
totrue
on the JS model since newly created models will always be drafts.
Testing Done: |
|
|||||||||
---|---|---|---|---|---|---|---|---|---|---|
Commits: |
|
|||||||||
Diff: |
Revision 5 (+474 -46) |
Checks run (2 succeeded)

Change Summary:
- Moved to RB6.
Commits: |
|
||||||
---|---|---|---|---|---|---|---|
Branch: |
|
||||||
Diff: |
Revision 6 (+488 -46) |
Checks run (2 succeeded)

Change Summary:
- Updated to work with the TS/spina version of the file attachment model.
Commits: |
|
||||||
---|---|---|---|---|---|---|---|
Diff: |
Revision 7 (+478 -40) |
Checks run (2 succeeded)
-
Most of this change looks perfect. The big part is ensuring our query counts don't balloon.
-
reviewboard/attachments/models.py (Diff revision 7) My concern is that this can easily lead to ballooning queries in any typical usage. Every
is_draft
is going to check upwards of 3 tables, so if we have 10 attachments, that's 30 queries.We have this same problem in other models, but also a solution. We can set precomputed state to check instead of assuming a query must be performed. Maybe this is a
_is_draft
flag, or maybe it's a flag for the review request or inactive review request.In any case, code fetching file attachments should know which they're fetching from (and
review_request
/inactive_review_request
are mutually-exclusive), so this state can be set.We actually have a
_review_request
, used byget_review_request()
, so there's precedence here (but we'd need different state, since I think_review_request
will be set for either case).The goal would be to avoid any queries from this function when loading the review request page or via the API.
This should probably also be a
@cached_property
. -
-

Change Summary:
Posting my WIP code for trying to reduce queries when calling
is_draft
Summary: |
|
||||||
---|---|---|---|---|---|---|---|
Commits: |
|
||||||
Diff: |
Revision 8 (+982 -58) |
Checks run (1 failed, 1 succeeded)
flake8
-
reviewboard/attachments/models.py (Diff revision 8) line too long (85 > 79 characters) Column: 80 Error code: E501
-
reviewboard/webapi/resources/base_review_request_file_attachment.py (Diff revision 8) at least two spaces before inline comment Column: 47 Error code: E261