ThreeSixtyGiving / datastore

A Data Store application for 360Giving
GNU Affero General Public License v3.0
0 stars 1 forks source link

API Performance Improvements #186

Closed R2ZER0 closed 7 months ago

R2ZER0 commented 7 months ago

This PR improves the performance of API OrgGrantsMade and OrgGrantsReceived about 100x, by adding denormalised convenience fields to Grant model with recipient/funder org_ids with database indexes, eliminating the need to join with Recipient / Funder tables each query.

Code to load grant data into the db has been updated to also add these new fields.

Existing Grants are updated using a 3-step migration:

  1. The new fields are added nullable, default NULL.
  2. Data migration runs SQL to populate the new fields in existing Grants.
  3. The new fields are altered to be non-nullable, all newly created Grants must specify the fields.

Given the new fields are non-nullable, and both existing load management commands are updated, it should be very unlikely that new Grants are created without the new fields properly populated or get out of sync.

With the goal of improving performance, this PR also: