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

[RHCLOUD-30109] Batch updates for last-visited-pages #1959

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

BlakeHolifield
Copy link
Contributor

Migrates the useLastVisitedPages hook to only push batch updates to the API

  • When the page is hidden for 20 seconds, the user's last 10 pages from localStorage will be saved in the DB
  • Every 3 minutes, the user's last 10 pages from localStorage are saved in the DB
  • In the event that localStorage is cleared, the state is set from the DB

@BlakeHolifield BlakeHolifield force-pushed the RHCLOUD-30109 branch 5 times, most recently from 146892f to 1a9584e Compare January 19, 2024 15:44
@BlakeHolifield BlakeHolifield marked this pull request as ready for review January 19, 2024 17:27
console.error('Unable to update last visited pages!', error);
}
// Save state from localStorage on an interval
setInterval(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You have to clear the interval in the useEffect cleanup phase. Currently this can cause memory leaks.

}
// Save state from localStorage on an interval
setInterval(async () => {
await updateMostRecentPages();
Copy link
Contributor

Choose a reason for hiding this comment

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

No reason to await this call. We are not working with the return value.

return () => {
titleObserver?.disconnect();
postDataDebounced?.cancel();
document.removeEventListener('visibilitychange', handleVisibilityChange);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also clear the inactiveTimeout.current here if it exists.

const lastVisited = localStorage.getItem(LAST_VISITED_FLAG);
if (lastVisited) {
const lastVisitedLocal = localStorage.getItem(LAST_VISITED_FLAG);
const getInitialPages = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function should be defined out of the effect.

@BlakeHolifield BlakeHolifield force-pushed the RHCLOUD-30109 branch 2 times, most recently from c365daa to 4907546 Compare February 1, 2024 18:37
@@ -1,6 +1,6 @@
{
"name": "@redhat-cloud-services/chrome",
"version": "1.0.7",
"version": "1.0.8",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is automated no need to bump the version manually.

@Hyperkid123 Hyperkid123 added the release Once merged it will trigger bugfix release label Feb 2, 2024
@Hyperkid123 Hyperkid123 merged commit 4ff412c into master Feb 2, 2024
3 checks passed
@nacho-bot
Copy link
Collaborator

                      :soon::shipit::octocat:
     :bug:Shipit Squirrel has this release bugfix surrounded, be ready for a new version:beetle:

@nacho-bot
Copy link
Collaborator

     🌱 🌸 🌷 🌻 🌟 New version of package has been released 🌟 🌻 🌷 🌸 🌱

                The release is available on:

          :package:@redhat-cloud-services/chrome/v/1.0.8📦

             :boom:This feature is brought to you by probot🚀

@nacho-bot nacho-bot added the released Pr has been released label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release Once merged it will trigger bugfix release released Pr has been released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants