-
Notifications
You must be signed in to change notification settings - Fork 895
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
Cache heartbeats one per date #5945
Conversation
|
packages/app/src/heartbeatService.ts
Outdated
} from './types'; | ||
|
||
const MAX_HEADER_BYTES = 1000; |
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.
Does it matter whether or not this is exactly 1kb?
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.
It's a somewhat arbitrary estimate intended to provide enough padding so the total header size, including headers from other sources, won't exceed 2KB so no, but it will probably look cleaner if I put 1024.
packages/app/src/heartbeatService.ts
Outdated
}; | ||
this._heartbeatsCache!.push(heartbeatsEntry); | ||
// There is no entry for this date. Create one. | ||
this._heartbeatsCache!.push({ date, userAgent }); |
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.
Can you get rid of the !
assertion now that it's explicitly set on line 92?
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.
Thanks, done.
return headerString; | ||
} | ||
} | ||
|
||
function getUTCDateString(): string { | ||
const today = new Date(); | ||
return today.toISOString().substring(0,10); | ||
return today.toISOString().substring(0, 10); |
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.
(small nit) maybe add a comment saying what part of the date string is retained after the substring operation?
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.
Good idea, done.
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.
Removed the more rigorous byte count function that covers all unicode possibilities because we're doing the count on the final base64 string, which will always be 1 byte per character because allowed characters are restricted to A-Z,a-z,0-9,/+=
packages/app/src/heartbeatService.ts
Outdated
} from './types'; | ||
|
||
const MAX_HEADER_BYTES = 1000; |
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.
It's a somewhat arbitrary estimate intended to provide enough padding so the total header size, including headers from other sources, won't exceed 2KB so no, but it will probably look cleaner if I put 1024.
packages/app/src/heartbeatService.ts
Outdated
}; | ||
this._heartbeatsCache!.push(heartbeatsEntry); | ||
// There is no entry for this date. Create one. | ||
this._heartbeatsCache!.push({ date, userAgent }); |
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.
Thanks, done.
return headerString; | ||
} | ||
} | ||
|
||
function getUTCDateString(): string { | ||
const today = new Date(); | ||
return today.toISOString().substring(0,10); | ||
return today.toISOString().substring(0, 10); |
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.
Good idea, done.
author Kai Wu <[email protected]> 1645732197 -0800 committer Christina Holland <[email protected]> 1645750725 -0800 Add Changeset for pull/5762 (#6030) * Create pretty-mayflies-worry.md * Update pretty-mayflies-worry.md Move based indexedDB operations to util add tests Fix year use idb clean up Add comments to HeartbeatService interface methods Cache heartbeats one per date (#5945)
Heartbeats need to be sent in a format where they are grouped by user agent, but some client-side functionality (such as removing records older than 30 days and limiting the header size) is easier to implement when the heartbeats are grouped by date. This change will group the records by date in client-side memory and storage, and convert it to the standard by-user-agent format when creating a header string to send to the backend.