From e01b00eab71f7b5c0b994c51d8b4e1b37babdb78 Mon Sep 17 00:00:00 2001 From: Jack Case Date: Mon, 5 Jan 2026 20:58:34 +0000 Subject: [PATCH] start working on slopstore class analogous to checkcache class --- spec/indexeddb_spec.js | 161 +++++++++++++++++++++++++---------------- src/indexed-db.ts | 8 ++ 2 files changed, 108 insertions(+), 61 deletions(-) diff --git a/spec/indexeddb_spec.js b/spec/indexeddb_spec.js index eb4e888..b327f09 100644 --- a/spec/indexeddb_spec.js +++ b/spec/indexeddb_spec.js @@ -3,11 +3,7 @@ import { openDB, deleteDB } from "../scripts/idb/index.js" const MAX_TIMESTAMP_DIFFERENCE = 3 -xdescribe("sanity check", () => { - it("works", () => { - expect(true).toBeTrue() - }) -}) +let mock_clock = jasmine.clock().install() describe("SlopDB", () => { @@ -38,11 +34,8 @@ describe("SlopDB", () => { describe("version 2", () => { let slopdb - let mock_clock beforeAll(() => { - const j_clock = jasmine.clock() - mock_clock = j_clock.install() mock_clock.mockDate(new Date(2020, 1, 1)) }) @@ -61,60 +54,106 @@ describe("SlopDB", () => { // slopdb_v2.db.close() }) - it("caches a checked url", async () => { - const cache = slopdb.check_cache - expect(cache).toBeInstanceOf(CheckCache) - - const slop_url = new URL("https://sloppy-slop.com/sloparticle") - - const new_item = await cache.store(slop_url.toString()) - const store_time = Date.now() - - mock_clock.tick(1000) - const cached_item = await cache.get(slop_url.toString()) - - expect(cached_item.url).toEqual(slop_url.toString()) - expect(new_item.check_timestamp).toBeCloseTo(store_time) - expect(new_item.check_timestamp).toBeGreaterThan(store_time - MAX_TIMESTAMP_DIFFERENCE) - }) - - it("updates a cached url's timestamp when it is accessed", async () => { - - - const cache = slopdb.check_cache - - const slop_url = new URL("https://sloppy-slop.com/sloparticle") - await cache.store(slop_url.toString()) - const store_time = Date.now() - - mock_clock.tick(1000 * 30) - - const cached_item = await cache.get(slop_url.toString()) - expect(cached_item.check_timestamp).toBeGreaterThan(store_time + 10) - }) - - it("evicts the least recently accessed URL when an item is added to a full cache", async () => { - const cache = slopdb.check_cache - cache.cache_capacity = 2 - - const slop_url = new URL("https://sloppy-slop.com/sloparticle") - await cache.store(slop_url.toString()) - - mock_clock.tick(1000) - - const slop_url2 = new URL("https://sloppy-slop.com/sloparticle2") - await cache.store(slop_url2.toString()) - - mock_clock.tick(1000) - - const slop_url3 = new URL("https://sloppy-slop.com/sloparticle3") - await cache.store(slop_url3.toString()) - - const get_slop1 = await cache.get(slop_url.toString()) - expect(get_slop1).toBeUndefined() - expect(cache.size).toEqual(2) - }) + }) }) + +describe("CheckCache", () => { + let db + let slopdb + + beforeAll(() => { + mock_clock.mockDate(new Date(2020, 1, 1)) + }) + + beforeEach(async () => { + await deleteDB("SlopDB") + slopdb = new SlopDB(2) + await slopdb.db_opened() + db = slopdb.db + }) + + afterEach(() => { + db.close() + }) + + it("caches a checked url", async () => { + const cache = slopdb.check_cache + expect(cache).toBeInstanceOf(CheckCache) + + const slop_url = new URL("https://sloppy-slop.com/sloparticle") + + const new_item = await cache.store(slop_url.toString()) + const store_time = Date.now() + + mock_clock.tick(1000) + const cached_item = await cache.get(slop_url.toString()) + + expect(cached_item.url).toEqual(slop_url.toString()) + expect(new_item.check_timestamp).toBeCloseTo(store_time) + expect(new_item.check_timestamp).toBeGreaterThan(store_time - MAX_TIMESTAMP_DIFFERENCE) + }) + + it("updates a cached url's timestamp when it is accessed", async () => { + + + const cache = slopdb.check_cache + + const slop_url = new URL("https://sloppy-slop.com/sloparticle") + await cache.store(slop_url.toString()) + const store_time = Date.now() + + mock_clock.tick(1000 * 30) + + const cached_item = await cache.get(slop_url.toString()) + expect(cached_item.check_timestamp).toBeGreaterThan(store_time + 10) + }) + + it("evicts the least recently accessed URL when an item is added to a full cache", async () => { + const cache = slopdb.check_cache + cache.cache_capacity = 2 + + const slop_url = new URL("https://sloppy-slop.com/sloparticle") + await cache.store(slop_url.toString()) + + mock_clock.tick(1000) + + const slop_url2 = new URL("https://sloppy-slop.com/sloparticle2") + await cache.store(slop_url2.toString()) + + mock_clock.tick(1000) + + const slop_url3 = new URL("https://sloppy-slop.com/sloparticle3") + await cache.store(slop_url3.toString()) + + const get_slop1 = await cache.get(slop_url.toString()) + expect(get_slop1).toBeUndefined() + expect(cache.size).toEqual(2) + }) +}) + +describe("SlopStore", () => { + let db + let slopdb + + beforeAll(() => { + mock_clock.mockDate(new Date(2020, 1, 1)) + }) + + beforeEach(async () => { + await deleteDB("SlopDB") + slopdb = new SlopDB(2) + await slopdb.db_opened() + db = slopdb.db + }) + + afterEach(() => { + db.close() + }) + + it("passes", () => { + expect(true).toBeTrue() + }) +}) diff --git a/src/indexed-db.ts b/src/indexed-db.ts index c6fe3bc..2242681 100644 --- a/src/indexed-db.ts +++ b/src/indexed-db.ts @@ -55,6 +55,14 @@ export class SlopStore { constructor(slopdb: IDBPDatabase) { this.slopdb = slopdb } + + async store(domain: string, path: string) { + + } + + async get(url: string) { + + } } export class SlopDB {