-
Notifications
You must be signed in to change notification settings - Fork 35
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
[MB-6628] Use EagerPreload to improve performance in some key spots #5880
Changes from all commits
aa3f68f
6e2df41
c1bd499
b6c4cc4
ace8ff6
b02a01c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,12 @@ func (f moveOrderFetcher) ListMoveOrders(officeUserID uuid.UUID, params *service | |
// Adding to an array so we can iterate over them and apply the filters after the query structure is set below | ||
options := []QueryOption{branchQuery, locatorQuery, dodIDQuery, lastNameQuery, dutyStationQuery, moveStatusQuery, gblocQuery, sortOrderQuery} | ||
|
||
query := f.db.Q().Eager( | ||
query := f.db.Q().EagerPreload( | ||
"Orders.ServiceMember", | ||
"Orders.NewDutyStation.Address", | ||
"Orders.OriginDutyStation", | ||
"Orders.OriginDutyStation.Address", | ||
// See note further below about having to do this in a separate Load call due to a Pop issue. | ||
// "Orders.OriginDutyStation.TransportationOffice", | ||
"Orders.Entitlement", | ||
"MTOShipments", | ||
"MTOServiceItems", | ||
|
@@ -79,14 +81,6 @@ func (f moveOrderFetcher) ListMoveOrders(officeUserID uuid.UUID, params *service | |
} | ||
} | ||
|
||
if err != nil { | ||
switch err { | ||
case sql.ErrNoRows: | ||
return []models.Move{}, 0, services.NotFoundError{} | ||
default: | ||
return []models.Move{}, 0, err | ||
} | ||
} | ||
Comment on lines
-82
to
-89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this appears to be a leftover. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed the if statement check on line 9 doesn't look for ErrNoRows to return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must have miss read the line numbers. I believe I meant the one on line 32 as it doesn't return the NotFoundError like the one you deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. That query is just getting the office user's associated transportation office's GBLOC to use as a filter in the next query for the TOO queue data. It should always return a record unless something really funky is going on because all the parts of that association are required in the DB, so not specifically looking for |
||
// Pass zeros into paginate in this case. Which will give us 1 page and 20 per page respectively | ||
if params.Page == nil { | ||
params.Page = swag.Int64(0) | ||
|
@@ -114,11 +108,21 @@ func (f moveOrderFetcher) ListMoveOrders(officeUserID uuid.UUID, params *service | |
count := query.Paginator.TotalEntriesSize | ||
|
||
for i := range moves { | ||
// Due to a bug in pop (https://github.com/gobuffalo/pop/issues/578), we | ||
// cannot eager load the address as "OriginDutyStation.Address" because | ||
// OriginDutyStation is a pointer. | ||
// There appears to be a bug in Pop for EagerPreload when you have two or more eager paths with 3+ levels | ||
// where the first 2 levels match. For example: | ||
// "Orders.OriginDutyStation.Address" and "Orders.OriginDutyStation.TransportationOffice" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could provide an endpoint to GetDutyStation and avoid the 3+ level nesting in general. DutyStation addresses don't change too much so it's not a huge deal not to have all the data in the fetchMTOUpdate. We could just return name and id. Not necessary change for this pr but wondered what you thought. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting bug, I think we have a few other places that such things happen so it's good to have documented. That said having a get duty station end point might make sense given they won't change much and it seems likely the prime will have a list of them as well. Totally agree that this isn't something we need for this PR but worth considering. @shimonacarvalho How much do we expect the prime to call fetch-mto-updates given they will be sent the information via the webhook notification. Or will they need to call it after receiving the notification? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So this particular query is fetching the data used in the TOO queue, not
For this PR, I mainly focused on optimizing what was already there and intentionally not changing the data returned to avoid accidentally breaking something else in the process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh my bad.
Yes, I just fixed up getMTO and it's really good for returning everything in a single mto. Easy to move from support --> prime. I think the challenge with fetchMTOUpdates is that its real value to the overall API is returning mtos where ANY data on the mto has changed since a certain date. However that is not working right now, it doesn't "deep-check" nested updatedAts. So it really needs a full rethink/rewrite which we haven't been able to get prioritization on.
@gidjin I just don't know honestly, since we have no Prime to ask. But i believe we need to make it work properly, with the since feature. Because even if push notifications works well and they get all the data they need normally, at some point when push fails (a cert expires or whatever) they will have to resync using fetch. |
||
// In those cases, only the last relationship is loaded in the results. So, we can only do one of the paths | ||
// in the EagerPreload above and request the second one explicitly with a separate Load call. | ||
// | ||
// Note that we also had a problem before with Eager as well. Here's what we found with it: | ||
// Due to a bug in pop (https://github.com/gobuffalo/pop/issues/578), we | ||
// cannot eager load the address as "OriginDutyStation.Address" because | ||
// OriginDutyStation is a pointer. | ||
if moves[i].Orders.OriginDutyStation != nil { | ||
f.db.Load(moves[i].Orders.OriginDutyStation, "Address", "TransportationOffice") | ||
loadErr := f.db.Load(moves[i].Orders.OriginDutyStation, "TransportationOffice") | ||
if loadErr != nil { | ||
return []models.Move{}, 0, err | ||
} | ||
} | ||
} | ||
|
||
|
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.
I added the
fk_id
struct tags here to workaround a Pop issue.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.
Thanks for documenting it! 🥳