Skip to content
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

OBPIH-5610 Significant performance issues with Export Orders #4013

Closed
wants to merge 4 commits into from

Conversation

jmiranda
Copy link
Member

@jmiranda jmiranda commented May 2, 2023

No description provided.

@jmiranda jmiranda requested a review from awalkowiak May 2, 2023 19:54
@drodzewicz drodzewicz closed this May 4, 2023
@drodzewicz drodzewicz reopened this May 4, 2023
@kchelstowski kchelstowski added the warn: do not merge Marks a pull request that is not yet ready to be merged label May 4, 2023
@kchelstowski
Copy link
Collaborator

Marked as "do not merge", since there are some differences visible in table vs csv

`order`.order_number as order_number,
order_item.id as order_item_id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was causing the problem of duplicates results, e.g. I was getting some weird order_id here when supposed to get only order_item_id:
Screenshot from 2023-05-09 17-51-33

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the column order issue.

SQLQuery sqlQuery = sessionFactory.currentSession.createSQLQuery(query)
final count = sqlQuery.with {
setString("orderId", order.id)
setString("prepaymentTypeCode", InvoiceTypeCode.PREPAYMENT_INVOICE.toString())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the ticket, I'm not sure this is correct. If there are requirements for excluding prepayment invoices in the "invoiced" count, then we can move this into the query (we don't need to use query parameters).

Copy link
Collaborator

@kchelstowski kchelstowski May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explained in the ticket why they should be excluded and how prepayments are excluded now in this method:

Integer getQuantityInvoicedInStandardUom() {
return InvoiceItem.executeQuery("""
SELECT SUM(ii.quantity)
FROM InvoiceItem ii
JOIN ii.invoice i
JOIN ii.shipmentItems si
JOIN si.orderItems oi
WHERE oi.id = :id
AND i.datePosted IS NOT NULL
""", [id: id])?.first() ?: 0
}

I've added it as query parameters to follow the convention you did with orderId - I didn't wanna mix things up, to have one parameter via query parameters, and one inside the query directly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/openboxes/openboxes/blob/develop/grails-app/migrations/views/order-summary-helper-views.sql#LL87C43-L87C46 This one here is doing that for OrderSummary (I know it's not intuitive and requires at least a comment), Katarzyna also linked tickets regarding the functionality in the OBPIH-5610.

Copy link
Collaborator

@awalkowiak awalkowiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two comments in the code. I think we should split these two cases and we should not mix those two:

  1. Order.getInvoiceItems
  2. Order.getInvoicedOrderItems
    because these are two different things. The first one should not be used for getting invoiced items for PO (but currently this one is used)

@@ -155,7 +156,7 @@ class PurchaseOrderApiController {
order?.orderedOrderItems?.size() ?: 0,
order?.shippedOrderItems?.size() ?: 0,
order?.receivedOrderItems?.size() ?: 0,
order?.invoiceItems?.size() ?: 0,
invoiceService.countInvoicedOrderItems(order)?:0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order?.invoiceItems?.size() should not be used here at all in the beginning, because it's taking all invoice items instead of invoiced order items, plus I even left a comment above order?.invoiceItems some time ago that it should be used for one order only but not for a list of orders like it was used in this case.

Perhaps it would be better to add all these counts to the OrderSummary? We would have then everything in one place without the need to have additional queries. All orderedOrderItems, shippedOrderItems, receivedOrderItems, and invoicedOrderItems could be additionally (easily) calculated in the helper views and stored in the OrderSummary.

Refactoring or improving orderItem?.invoiceItems and orderItem?.quantityInvoicedInStandardUom should also be done definitely but it probably doesn't have to be done for PO export if were getting the item counts from view or the query that you created.

SQLQuery sqlQuery = sessionFactory.currentSession.createSQLQuery(query)
final count = sqlQuery.with {
setString("orderId", order.id)
setString("prepaymentTypeCode", InvoiceTypeCode.PREPAYMENT_INVOICE.toString())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/openboxes/openboxes/blob/develop/grails-app/migrations/views/order-summary-helper-views.sql#LL87C43-L87C46 This one here is doing that for OrderSummary (I know it's not intuitive and requires at least a comment), Katarzyna also linked tickets regarding the functionality in the OBPIH-5610.

@awalkowiak
Copy link
Collaborator

I am closing this one since it is fixed in another way in this PR #4027

@awalkowiak awalkowiak closed this May 18, 2023
@awalkowiak awalkowiak deleted the OBPIH-5610 branch May 18, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
warn: do not merge Marks a pull request that is not yet ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants