-
Notifications
You must be signed in to change notification settings - Fork 237
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
Conversation
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.