Skip to content

Do not send an ajax request if there no affected sections #31933

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

Merged
merged 6 commits into from
Mar 7, 2021

Conversation

ihor-sviziev
Copy link
Contributor

@ihor-sviziev ihor-sviziev commented Feb 2, 2021

Description (*)

In the customer data, we have a handler for all ajax requests. If we have some custom JS that sends POST, PUT or DELETE request, it tries to send a request to the backend to reload affected sections. As we had such a request by some tracking - these requests caused an additional request to the backend on all the pages that caused a significant load to the servers.

In case if there are no affected sections, it is still sending requests to the backend.

We got this issue when we created a mixin to the getAffectedSections for Magento_Customer/js/section-config and returning an empty array for our custom URL (request is sent not to Magento, so it can't affect any Magento sections).

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes magento/magento2#<issue_number>

Manual testing scenarios (*)

  1. Open app/code/Magento/Customer/view/frontend/web/js/section-config.js
  2. at the beginning of the getAffectedSections method add following code in console:
            if (typeof url === 'string' && url.indexOf('my-url-not-affecting-sections') !== -1) {
                return [];
            }

image
3. Open frontend
4. open developer tools, execute following JS:

jQuery.post('/my-url-not-affecting-sections');
  1. Go to the "network" tab in the developer tools, review the list of requests

Actual result:
image
❌ request for reloading customer sections was sent to the backend

Expected result
image
✔ request for reloading customer sections shouldn't be sent to the backend

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Do not send an ajax request if there no affected sections #31948: Do not send an ajax request if there no affected sections

@m2-assistant
Copy link

m2-assistant bot commented Feb 2, 2021

Hi @ihor-sviziev. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@ihor-sviziev
Copy link
Contributor Author

@magento run all tests

@ihor-sviziev
Copy link
Contributor Author

Note: I don't have enough experience with writing JS unit tests, so would be good if someone could help with it

@gabrieldagama
Copy link
Contributor

@magento create issue

@ihor-sviziev
Copy link
Contributor Author

@magento run all tests

@ihor-sviziev
Copy link
Contributor Author

@magento run Functional Tests B2B, Functional Tests EE, Sample Data Tests EE, Static Tests

@ihor-sviziev
Copy link
Contributor Author

@magento run Functional Tests B2B, Functional Tests EE

@m2-community-project m2-community-project bot added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Feb 3, 2021
@ihor-sviziev
Copy link
Contributor Author

@magento run Functional Tests B2B

Copy link
Contributor

@gabrieldagama gabrieldagama left a comment

Choose a reason for hiding this comment

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

Hi @engcom-Charlie, can you try to add test coverage on this one? I guess jasmine unit test could be an option, can you give it a try? Thanks!

@ihor-sviziev
Copy link
Contributor Author

@magento run Functional Tests B2B

@gabrieldagama
Copy link
Contributor

@magento run all tests

@magento-engcom-team
Copy link
Contributor

Hi @gabrieldagama, thank you for the review.
ENGCOM-8779 has been created to process this Pull Request
✳️ @gabrieldagama, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@gabrieldagama
Copy link
Contributor

@magento run all tests

@gabrieldagama gabrieldagama added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Feb 17, 2021
@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel engcom-Hotel self-assigned this Feb 17, 2021
@engcom-Hotel
Copy link
Contributor

@magento run Functional Tests B2B

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run Functional Tests B2B

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Manual testing scenario:

  1. Open app/code/Magento/Customer/view/frontend/web/js/section-config.js
  2. at the beginning of the getAffectedSections method add following code in console:
            if (typeof url === 'string' && url.indexOf('my-url-not-affecting-sections') !== -1) {
                return [];
            }

image
3. Open frontend
4. open developer tools, execute following JS:

jQuery.post('/my-url-not-affecting-sections');
  1. Go to the "network" tab in the developer tools, review the list of requests

Before: ✖️ request for reloading customer sections was sent to the backend

2021-02-18_08-53

After: ✔️ request for reloading customer sections wasn't sent to the backend

2021-02-18_09-04

Was checked general customer functionality, and everything works as expected.
Screenshot from 2021-02-18 10-20-35

@ihor-sviziev
Copy link
Contributor Author

Hi @gabrieldagama,
Could you check one more PR in similar area? #31940

@m2-assistant
Copy link

m2-assistant bot commented Mar 7, 2021

Hi @ihor-sviziev, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Customer Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S1 Affects critical data or functionality and forces users to employ a workaround. Type: Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue] Do not send an ajax request if there no affected sections
5 participants