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:
The new fields are added nullable, default NULL.
Data migration runs SQL to populate the new fields in existing Grants.
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:
Updates API queries to specifically ignore the default order_by on Publisher
Updates OrgGrantsMade/Received to prefetch Publisher data for the Grants
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:
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: