mozilla / code-review

Automated static analysis & linting bot for Mozilla repositories
Mozilla Public License 2.0
56 stars 42 forks source link

Simplify bulk issues creation #2536

Closed La0 closed 1 day ago

La0 commented 1 day ago

Refs #2260

Closes https://mozilla.sentry.io/issues/6072452921 (a lot of 500s on both instances)

I noticed an important issue on the backend that prevent issues creation when an issue is already linked to a revision through a previous diff. This case happens often now that we have de-duplicated issues.

The bulk endpoint was iterated over recently, bringing too much complexity.

I was able to simplify it so it runs in 4 steps:

  1. create all issues in a single bulk_create call, using unicity constraints to prevent duplications
  2. retrieve all issues from DB to get existing IDs (as bulk_create otherwise provides its generated but non-commited IDs)
  3. directly create all issue links in a single bulk_create call, using unicity constraints to prevent duplications
  4. build list of dicts for specific serializations

This removes support for an edge-case: calling multiple times the endpoint with the same payload with NULL values in line, char, nb_lines will re-create the same IssueLink. This case should never happen in practice, but the existing DB constraint does not catch it due to a Database limitation. I'll file an issue to work on