aboutsummaryrefslogtreecommitdiffstats
path: root/tools/feed-cache-test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-01 06:49:19 -0700
committerAdam Soltys <[email protected]>2026-10-01 06:49:19 -0700
commit68ff290e07c0e1786cf8b8f3a87e38872ad7f8ba (patch)
treec85847c8f4a06b0a6b7dab8abb2d2eb54fefa226 /tools/feed-cache-test.js
parent4b3291fdbd0b34b4d2df91a59bea93885de29508 (diff)
parent5ff909d37fe32ba04a841941593d95c7b3498ec3 (diff)
downloadcoinosv3-68ff290e07c0e1786cf8b8f3a87e38872ad7f8ba.tar.gz
coinosv3-68ff290e07c0e1786cf8b8f3a87e38872ad7f8ba.zip
Merge prod into master
Diffstat (limited to 'tools/feed-cache-test.js')
-rw-r--r--tools/feed-cache-test.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/tools/feed-cache-test.js b/tools/feed-cache-test.js
index 995e01a..3df9447 100644
--- a/tools/feed-cache-test.js
+++ b/tools/feed-cache-test.js
@@ -12,14 +12,28 @@ storage.setItem('wallet:funds', 'untouched');
assert.equal(cache.read('following').length, 30);
assert.equal(JSON.parse(storage.getItem('wallet:feedNotes')).notes.length, 30);
for (let i = 0; i < 5; i++) cache.save('custom' + i, notes);
-assert.equal(cache.read('following').length, 0);
-assert.equal([...values.keys()].filter((k) => k.includes('feedNotes')).length, 4);
-cache.read('custom1');
-cache.save('custom5', notes);
-assert.equal(cache.read('custom2').length, 0);
+const stored = (id) => JSON.parse(storage.getItem(id === 'following' ? 'wallet:feedNotes' : 'wallet:feedNotes:' + id) || 'null');
+assert.equal(stored('following').notes.length, 5, 'a feed past the four most recent keeps seed posts');
+assert.equal(stored('custom4').notes.length, 30);
+assert.equal(cache.read('following').length, 5, 'and reads them back');
+for (let i = 5; i < 14; i++) cache.save('custom' + i, notes);
+assert.equal([...values.keys()].filter((k) => k.includes('feedNotes')).length, 12);
+assert.equal(stored('custom0'), null, 'the least recently read goes first');
+assert.equal(stored('custom3').notes.length, 5);
+cache.read('custom3'); cache.save('custom3', notes);
+assert.equal(stored('custom3').notes.length, 30, 'reopened, it gets a full page again');
+assert.equal(stored('custom10').notes.length, 5, 'and the oldest of the four drops to seed posts');
+// seeds warmed ahead never outrank or overwrite a feed that was read
+cache.seed('custom13', notes.slice(0, 2));
+assert.equal(stored('custom13').notes.length, 30);
+assert.equal(cache.has('warm'), false);
+cache.seed('warm', notes);
+assert.equal(cache.has('warm'), true);
+assert.equal(stored('warm').notes.length, 5);
+assert.equal(stored('custom13').notes.length, 30);
cache.save('big', notes.map((e) => ({ ...e, content: 'x'.repeat(15000) })));
assert([...values].filter(([k]) => k.includes('feedNotes')).reduce((n, [, v]) => n + v.length, 0) <= 256000);
time += 8 * 86400_000;
assert.equal(cache.read('big').length, 0);
assert.equal(storage.getItem('wallet:funds'), 'untouched');
-console.log('✓ legacy caches shrink; 30 posts/feed, four feeds, byte budget, LRU and seven-day expiry enforced');
+console.log('✓ legacy caches shrink; 30 posts for the four most recent feeds, 5 seed posts for up to 12, byte budget, LRU and seven-day expiry enforced');