mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-27 09:22:44 +00:00
Add garbage collection function to remove version data after specified period without update
This commit is contained in:
@@ -27,7 +27,7 @@ const Markdown = require('naturalcrit/markdown.js');
|
||||
const { DEFAULT_BREW_LOAD } = require('../../../../server/brewDefaults.js');
|
||||
const { printCurrentBrew, fetchThemeBundle } = require('../../../../shared/helpers.js');
|
||||
|
||||
import { updateHistory } from '../../utils/versionHistory.js';
|
||||
import { updateHistory, versionHistoryGarbageCollection } from '../../utils/versionHistory.js';
|
||||
|
||||
const googleDriveIcon = require('../../googleDrive.svg');
|
||||
|
||||
@@ -205,6 +205,7 @@ const EditPage = createClass({
|
||||
}));
|
||||
|
||||
updateHistory(this.state.brew);
|
||||
versionHistoryGarbageCollection();
|
||||
|
||||
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ export const HISTORY_PREFIX = 'HOMEBREWERY-HISTORY'
|
||||
// 4: 12 * 60, // 12 hours
|
||||
// 5: 2 * 24 * 60 // 2 days
|
||||
// };
|
||||
//
|
||||
// const GARBAGE_COLLECT_AT = 28 * 24 * 60; // 28 days
|
||||
|
||||
|
||||
// <=================== TEST VALUES STARTS ===================>
|
||||
|
||||
// Test values
|
||||
const HISTORY_SAVE_DELAYS = {
|
||||
@@ -17,6 +22,11 @@ const HISTORY_SAVE_DELAYS = {
|
||||
4: 4, // 4 minutes
|
||||
5: 5 // 5 minutes
|
||||
};
|
||||
const GARBAGE_COLLECT_DELAY = 10; // 10 minutes
|
||||
|
||||
// <==================== TEST VALUES ENDS ====================>
|
||||
|
||||
|
||||
|
||||
const DEFAULT_STORED_BREW = {
|
||||
shareId : 'default_brew',
|
||||
@@ -94,3 +104,18 @@ export function updateHistory(brew) {
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
export function versionHistoryGarbageCollection(){
|
||||
Object.keys(localStorage)
|
||||
.filter((key)=>{
|
||||
return key.startsWith(HISTORY_PREFIX);
|
||||
})
|
||||
.forEach((key)=>{
|
||||
const collectAt = new Date(JSON.parse(localStorage.getItem(key)).expireAt);
|
||||
collectAt.setMinutes(collectAt.getMinutes() + GARBAGE_COLLECT_DELAY);
|
||||
if(new Date() > collectAt){
|
||||
console.log('GARBAGE COLLECTION:', key);
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user