Skip to content

Commit

Permalink
Swap Ministers Index GraphQL #joins for #includes
Browse files Browse the repository at this point in the history
Because, despite looking very similar (to me), of these two methods,
ActiveRecord only treats #includes as eagerloading. (For anybody not
familiar, this results in lazy-loading, i.e. separate database queries
later on for any associations that are accessed in our code.)

With my local data, this reduced the number of database queries made in
order to serve the Ministers Index page from 1144 down to 280.
  • Loading branch information
mike3985 committed Dec 16, 2024
1 parent 358325e commit a6d02a4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/graphql/types/base_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.links_field(field_name_and_link_type, graphql_field_type)
define_method(field_name_and_link_type.to_sym) do
Edition
.live
.joins(document: { reverse_links: :link_set })
.includes(document: { reverse_links: :link_set })
.where(
document: { locale: "en" },
link_set: { content_id: object.content_id },
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/ministers_index_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MinistersIndexPersonLinks < Types::BaseObject
def role_appointments
Edition
.live
.joins(
.includes(
document: {
reverse_links: { # role -> role_appointment
link_set: {
Expand Down

0 comments on commit a6d02a4

Please sign in to comment.