-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce dataloader queries #3192
base: main
Are you sure you want to change the base?
Conversation
2d84d96
to
7e7c61f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes all seem ok to me.
But I've run the code locally and queried the prime minister page, which gives the role_appointments
links in a different order to those in the existing content item. It could be the order has changed since my old dump of the database, but I'd suggest trying this code on integration to double check the order has stays the same when querying against the same database.
7e7c61f
to
50c28a4
Compare
50c28a4
to
7894c42
Compare
Co-authored-by: Mike Patrick <mike.patrick2@digital.cabinet-office.gov.uk>
I'm not 100% sure about this change. We're experimenting with SELECTing subsets of an edition's columns and JOINed-tables' columns to improve the performance of our GraphQL resolvers. When you SELECT JOIN columns, Active Record helpfully just seems to dynamically add them as attributes to the model you're working with, which means that, e.g. SELECT editions.*, documents.content_id, documents.locale FROM editions INNER JOIN documents ON document.id = editions.document_id would result in instances of Edition with their own, native #content_id and #locale attributes. In those specific examples, the existing `delegate` doesn't appear to acknowledge these attributes and still attempts to lazy-load the edition's document to fetch them. Since that lazy-loading kinda defeats the point of the approach we're experimenting with, here's an alternative to `delegate` that first checks for pre-existing attributes of the same name. There could be better approaches than this worth exploring in the long run if we do stick with this SELECTing optimisation. (I don't think it's wise to use these Active Record models in such dramatically different ways in different parts of the codebase.)
We explicitly order the results by position, but we'll test this separately. We changed the Active Record code to use a UNION query, which has meant interweaving edition and link set links, breaking the order that these tests were implicitly depending on Co-authored-by: Mike Patrick <mike.patrick2@digital.cabinet-office.gov.uk>
We encountered an issue when creating an edition link separately to its edition (i.e. not using the `links_hash` transient/argument), whereby both a link set association was created even when explicitly creating an edition association Co-authored-by: Mike Patrick <mike.patrick2@digital.cabinet-office.gov.uk>
We found that the previous eager loading approach wasn't using joins effectively, so we're more manually crafting the queries to join in an efficient way. We also found that some associations we're still lazy loaded after the initial queries - this new approach avoids that issue For now we're selecting all columns from the editions table. We'll reduce the selections down to a subset in a later change The change to using a UNION affects the order of the resulting editions, so we've added a test to document our expectations Co-authored-by: Mike Patrick <mike.patrick2@digital.cabinet-office.gov.uk>
7894c42
to
70f046a
Compare
Trello
This optimises(?) the database queries in
LinkedToEditionsSource
andReverseLinkedToEditionsSource
, reducing them down to one query each (in practice, one query per level of depth in the GraphQL query). This is a change en route to selecting a subset of columns - we'll open a separate pull request for that changeWe're looking into the actual performance of this change at the minute but thought it was worth opening the pull request since the core bones are in place
This application is owned by the publishing platform team. Please let us know in #govuk-publishing-platform when you raise any PRs.
Follow these steps if you are doing a Rails upgrade.