Fossil SCM
Modify the purging of stale forum post drafts to happen on only one visit per 24 hours instead of a random chance on each visit, and make it async so it does not block the still-initializing page. Fix a 'this' mis-reference in fossil.storage.keys() uncovered by that change.
Commit
0db7eccd47f2e1295de01e2b6f9f314b5d55bc3896205976774ebb2fc2bad70c
Parent
9af97ebf35c0618…
2 files changed
+10
-2
+1
-1
+10
-2
| --- src/fossil.page.forumpost.js | ||
| +++ src/fossil.page.forumpost.js | ||
| @@ -1348,11 +1348,19 @@ | ||
| 1348 | 1348 | to start hidden so that it does not show up for no-JS |
| 1349 | 1349 | clients. */ |
| 1350 | 1350 | e.classList.remove('initially-hidden'); |
| 1351 | 1351 | }); |
| 1352 | 1352 | |
| 1353 | - if( plugInEditor && (Date.now() % 17 === 0) ){ | |
| 1353 | + if( plugInEditor ){ | |
| 1354 | 1354 | /* Purge old drafts only every now and then. */ |
| 1355 | - F.ForumPostEditor.purgeOldDrafts(/^draft-(reply|forumedit)-.*/)/*not purging forumnew*/; | |
| 1355 | + const now = Date.now(); | |
| 1356 | + const lastPurge = +F.storage.get('forum-drafts-last-purge', 0); | |
| 1357 | + if( now - lastPurge > (24 * 60 * 60 * 1000 /*1 day ms*/) ){ | |
| 1358 | + F.storage.set('forum-drafts-last-purge', now); | |
| 1359 | + setTimeout(()=>{ | |
| 1360 | + /* Don't block the UI while we're doing I/O */ | |
| 1361 | + F.ForumPostEditor.purgeOldDrafts(/^draft-(reply|forumedit)-.*/); | |
| 1362 | + }, 50); | |
| 1363 | + } | |
| 1356 | 1364 | } |
| 1357 | 1365 | })/*F.onPageLoad callback*/; |
| 1358 | 1366 | })(window.fossil); |
| 1359 | 1367 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -1348,11 +1348,19 @@ | |
| 1348 | to start hidden so that it does not show up for no-JS |
| 1349 | clients. */ |
| 1350 | e.classList.remove('initially-hidden'); |
| 1351 | }); |
| 1352 | |
| 1353 | if( plugInEditor && (Date.now() % 17 === 0) ){ |
| 1354 | /* Purge old drafts only every now and then. */ |
| 1355 | F.ForumPostEditor.purgeOldDrafts(/^draft-(reply|forumedit)-.*/)/*not purging forumnew*/; |
| 1356 | } |
| 1357 | })/*F.onPageLoad callback*/; |
| 1358 | })(window.fossil); |
| 1359 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -1348,11 +1348,19 @@ | |
| 1348 | to start hidden so that it does not show up for no-JS |
| 1349 | clients. */ |
| 1350 | e.classList.remove('initially-hidden'); |
| 1351 | }); |
| 1352 | |
| 1353 | if( plugInEditor ){ |
| 1354 | /* Purge old drafts only every now and then. */ |
| 1355 | const now = Date.now(); |
| 1356 | const lastPurge = +F.storage.get('forum-drafts-last-purge', 0); |
| 1357 | if( now - lastPurge > (24 * 60 * 60 * 1000 /*1 day ms*/) ){ |
| 1358 | F.storage.set('forum-drafts-last-purge', now); |
| 1359 | setTimeout(()=>{ |
| 1360 | /* Don't block the UI while we're doing I/O */ |
| 1361 | F.ForumPostEditor.purgeOldDrafts(/^draft-(reply|forumedit)-.*/); |
| 1362 | }, 50); |
| 1363 | } |
| 1364 | } |
| 1365 | })/*F.onPageLoad callback*/; |
| 1366 | })(window.fossil); |
| 1367 |
+1
-1
| --- src/fossil.storage.js | ||
| +++ src/fossil.storage.js | ||
| @@ -182,11 +182,11 @@ | ||
| 182 | 182 | }, |
| 183 | 183 | /** Returns an array of all keys currently in the storage. If full |
| 184 | 184 | is true then the keys include the storage key prefix, else |
| 185 | 185 | they don't. It should default to false but does not for |
| 186 | 186 | historical compatibility. */ |
| 187 | - keys: (full=true)=>{ | |
| 187 | + keys: function(full=true){ | |
| 188 | 188 | const li = Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)); |
| 189 | 189 | if( full ) return li; |
| 190 | 190 | const n = this.storageKeyPrefix.length; |
| 191 | 191 | return li.map(v=>v.substring(n)); |
| 192 | 192 | }, |
| 193 | 193 |
| --- src/fossil.storage.js | |
| +++ src/fossil.storage.js | |
| @@ -182,11 +182,11 @@ | |
| 182 | }, |
| 183 | /** Returns an array of all keys currently in the storage. If full |
| 184 | is true then the keys include the storage key prefix, else |
| 185 | they don't. It should default to false but does not for |
| 186 | historical compatibility. */ |
| 187 | keys: (full=true)=>{ |
| 188 | const li = Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)); |
| 189 | if( full ) return li; |
| 190 | const n = this.storageKeyPrefix.length; |
| 191 | return li.map(v=>v.substring(n)); |
| 192 | }, |
| 193 |
| --- src/fossil.storage.js | |
| +++ src/fossil.storage.js | |
| @@ -182,11 +182,11 @@ | |
| 182 | }, |
| 183 | /** Returns an array of all keys currently in the storage. If full |
| 184 | is true then the keys include the storage key prefix, else |
| 185 | they don't. It should default to false but does not for |
| 186 | historical compatibility. */ |
| 187 | keys: function(full=true){ |
| 188 | const li = Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)); |
| 189 | if( full ) return li; |
| 190 | const n = this.storageKeyPrefix.length; |
| 191 | return li.map(v=>v.substring(n)); |
| 192 | }, |
| 193 |