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

fix: Fixing localStorage overflow caused by unlimited logging of activityLog entries. Introduced sliding window of max 4000 items. #6

Open
wants to merge 1 commit into
base: 10.5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bundles/CoreBundle/Resources/public/js/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@

User.prototype.save = function () {
if (util.featureDetect('localStorage')) {
// Ensure activityLog doesn't eat up all the local storage.
// It is assumed 10MB of localStorage group space, activityLog
// entries can vastly vary in size e.g. for pageView entries due
// to the saved URL.
// For now 0.5 KB per log entry are assumed. Using a
// conservative 20% of the assumed available space as limit
// allows us to fill 2MB of storage which equals about 4000
// activityLog entries.
const activityLogLimit = 4000;
if (this.data.activityLog.length > activityLogLimit) {
util.logger.canLog('info') && console.info('[TARGETING] ' + this.data.activityLog.length + ' acitvityLog items exceed limit of ' + activityLogLimit + '. Evicting excess.', this);
this.data.activityLog = this.data.activityLog.slice(0, activityLogLimit);
}
localStorage.setItem("_ptg.user", JSON.stringify(this.data));
}

Expand Down