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

[sitecore-jss-nextjs]: Improve performance for redirects #SXA-7834 #2003

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

Conversation

sc-ruslanmatkovskyi
Copy link
Collaborator

@sc-ruslanmatkovskyi sc-ruslanmatkovskyi commented Dec 17, 2024

Description / Motivation

A condition for prefetch requests has been added to improve the performance of redirects.

Additionally, a condition has been added to handle Netlify requests to reduce server load.

Testing Details

  • Unit Test Added
  • Manual Test/Other (Please elaborate)

Types of changes

  • 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 change)

Copy link
Contributor

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

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

Looks as a good improvement! I added some comments
Of course you need to add unit tests, they are missing :)
We can jump on the call to discuss some uncertainties

Ruslan Matkovskyi added 3 commits December 20, 2024 12:37
…ded to improve the performance of redirects.

Additionally, a condition has been added to handle Netlify requests to reduce server load.
@sc-ruslanmatkovskyi sc-ruslanmatkovskyi force-pushed the bugifx/SXA-7834-improvement-perfomence-redirects branch from f67d456 to 9879878 Compare December 20, 2024 11:38
@sc-ruslanmatkovskyi sc-ruslanmatkovskyi changed the title [sitecore-jss-nextjs]: The cache of results of pattern has been added #SXA-7834 [sitecore-jss-nextjs]: Improve performance for redirects #SXA-7834 Dec 20, 2024
Copy link
Contributor

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

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

  1. I see that you removed caching mechanism, do we still need it for standard requests? Or it's enough to skip prefetch requests to get a stable performance?
  2. Unit tests are missing (e.g. new prefetch req case)

}

// Skip prefetch requests
if (this.isPrefetch(req)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add some explanation on the reason of skipping prefetch requests, for better understanding if other people will need to figure out the scenario

locale,
});
} else {
matchedQueryString = [
Copy link
Contributor

Choose a reason for hiding this comment

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

To me looks like this bunch of code does almost the same what getPermutedQueryMatch does
do you just need to use the same method?

pattern: redirect.pattern,
locale,
});
if (req.headers.get('cdn-loop') === NAME_NETLIFY) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better way to safely check for netlify? Env variables?
Another question - do we really need to do this check, since :261 line does almost the same what getPermutedQueryMatch does. Does it really optimize something? since the same reg exp is executed


const REGEXP_CONTEXT_SITE_LANG = new RegExp(/\$siteLang/, 'i');
const REGEXP_ABSOLUTE_URL = new RegExp('^(?:[a-z]+:)?//', 'i');
const NAME_NETLIFY = 'netlify';
Copy link
Contributor

Choose a reason for hiding this comment

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

In case you leave netlify check (see my question below)

Suggested change
const NAME_NETLIFY = 'netlify';
const NETLIFY_CDN_HEADER = 'netlify';

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.

2 participants