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

Fixes consumables' checkout 500 error and memory exhaustion #15785

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Godmartinz
Copy link
Collaborator

Description

This fixes the 500 error upon consumable checkout and adds try/catch around the array creation and db transaction.
Speaking of a DB transaction, this refactors the store method by cutting back on querying the users table too many times and utilizes a DB transaction.
This also caps the checkout quantity to 10 thousand. Performance gets shotty above that and can error sometimes.
image

If an error occurs or memory exhaustion it will no longer 500 but return an error message:
image

Fixes #[sc-27379]

Type of change

Please delete options that are not relevant.

  • [x ] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Configuration:

  • PHP version:
  • MySQL version
  • Webserver version
  • OS version

Checklist:

Copy link

what-the-diff bot commented Nov 7, 2024

PR Summary

  • Database Facade Implementation
    The addition of the DB facade now allows us to handle data transactions with the database seamlessly.

  • Adjustment of Consumable Lookup
    This change is about modifying the system's way of searching for consumable items. It is now done in a straightforward way, hence quicker and more efficient.

  • Introduction of Quantity Limit Check
    In order to enhance the overall performance and better manage memory, a check has been put in place to restrict checkouts to a maximum of 10,000 items at a time.

  • Refurbishing of Error Messages
    Two new types of error messages have been added, i.e., 'checkout_error' and 'large_quantity_error'. These new additions will enable users to understand and fix the errors more efficiently.

  • Data Attachment Consolidation
    Replacing the multiple-transaction user attachment with a single database transaction improves the overall system performance and makes the code structure cleaner.

  • Reinforcement of Error Handling
    In an effort to catch and deal with potential exceptions adequately, the user attachment logic has been enclosed within a try-catch block. This ensures effective exception handling, providing a user-friendly error resolution process.

  • Optimised Request Handling
    The process for adding checkout_to_type and assigned_user to a request has been simplified. It now consists of a single 'add' call, making the code easier to understand and manage.

Copy link
Collaborator

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

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

One comment about something we might want to change but good other than that 👍🏾

event(new CheckoutableCheckedOut($consumable, $user, auth()->user(), $request->input('note')));
});
}catch(\Exception $e){
report ($e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the only thing that we might not want to include. I'll leave it up to @snipe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants