fecgov / fecfile-web-api

Back-end API for FECfile application
Other
8 stars 2 forks source link

Performance Improvements - Refactor report serializer can_delete() method #918

Closed Elaine-Krauss-TCG closed 1 month ago

Elaine-Krauss-TCG commented 3 months ago

The report serializer can_delete() method needs refactoring to improve performance: https://github.com/fecgov/fecfile-web-api/blob/release/sprint-42/django-backend/fecfiler/reports/serializers.py#L144-L177

QA Notes

Provide performance results in the comments.

Following the changes, there should be no visible changes when interacting with reports. You should be able to load the Manage Reports table, load individual reports, and add and view Report Memos without issue.

FECFILE-1430

DEV Notes

The to_representation method in the report serializer has an out-sized impact on response times. The biggest factor here is the can_delete method, which can take upwards of 1,000ms to run when a committee has tens of thousands of transactions in it.

  1. Improve performance of added annotation where used.
  2. Remove addition of annotation when not needed in response.

Design

null

FECFILE-1430

exalate-issue-sync[bot] commented 2 months ago

Matt Travers commented: From CR, the trigger is not updating the can_delete for a report to false when adding a transaction to the report. Sending back to In Progress.

exalate-issue-sync[bot] commented 2 months ago

Matt Travers commented: The move of the can_delete() code to the create/update has slowed the performance of those actions significantly. Moving ticket back to In Progress to reassess strategy.

exalate-issue-sync[bot] commented 2 months ago

Sasha Dresden commented: I've reworked the logic of the trigger and it has significantly improved performance for me. Here's some results from Locust generating

Requests Median (ms) 95%ile (ms) 99%ile (ms) Average (ms) Min (ms) Max (ms)

223 83 97 100 84.12 72 117 1652 88 110 120 89.39 72 166 5035 100 120 140 101.39 72 199 10046 120 160 180 117.4 72 259 15007 130 190 220 133.96 72 378 18171 140 210 250 144.96 72 574 20000 150 260 320 156.4 72 771

exalate-issue-sync[bot] commented 2 months ago

Matt Travers commented: Passes CR. Sending to QA.

exalate-issue-sync[bot] commented 1 month ago

Shelly Wise commented: QA review consisted of visual inspection when interacting with reports was able to load the Manage Reports table, load individual reports, and add and view Report Memos without issue. DEV provided Locust generation as denoted.

QA Review Completed. Moved to Stage Ready.

exalate-issue-sync[bot] commented 1 month ago

Sprint accepted by Paul Clark during sprint review on 8/20/2024.