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

ai_user cookie not present after reenabling the cookie #1585 #1632

Merged
merged 2 commits into from
Aug 11, 2021

Conversation

MSNev
Copy link
Collaborator

@MSNev MSNev commented Aug 11, 2021

  • Add optimization to avoid always updating the cookie value

- Add optimization to avoid always updating the cookie value
@@ -75,6 +83,8 @@ export class User implements IUserContext {
const params = cookie.split(User.cookieSeparator);
if (params.length > 0) {
_self.id = params[0];
// we already have a cookie
_self.isUserCookieSet = !!_self.id;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we successfully read a value from the cookie then we assume that the cookie was set.

@@ -98,7 +108,7 @@ export class User implements IUserContext {
// set it to 365 days from now
// 365 * 24 * 60 * 60 = 31536000
const oneYear = 31536000;
_cookieManager.set(_storageNamePrefix(), cookie, oneYear);
_self.isUserCookieSet = _cookieManager.set(_storageNamePrefix(), cookie, oneYear);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use new response that tells us if the cookie was really set.

let user_cookie = _generateNewCookie(user_id);
_setUserCookie(user_cookie.join(User.cookieSeparator));
// Optimizations to avoid setting and processing the cookie when not needed
if (_self.id !== userId || !_self.isUserCookieSet) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add an extra performance based check so we don't try and set the cookie if

  • The value was already set
  • The new userId is the same as the previous one.

}

_processTelemetryInternal(event, itemCtx);

if (theContext.user && theContext.user.isNewUser) {
theContext.user.isNewUser = false;
if (userCtx && userCtx.isNewUser) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Simple minification improvement which also has a miner perf improvement.

/**
* A flag indicating whether the user cookie has been set
*/
isUserCookieSet?: boolean;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding as optional so we don't break anyone who is using this interface

*/
set(name: string, value: string, maxAgeSec?: number, domain?: string, path?: string): void;
set(name: string, value: string, maxAgeSec?: number, domain?: string, path?: string): boolean;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While this is a change to the signature of the function, it should be backward compatible as previously it was void.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is also used by internally as well, so this should be compatible with that as well.

@MSNev MSNev added this to the 2.x.x (Next Release) milestone Aug 11, 2021
@MSNev MSNev merged commit 039b843 into master Aug 11, 2021
@MSNev MSNev deleted the MSNev/CookieMgrUpdates branch November 13, 2021 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants