URL objects are being annoying, just store strings and make a URL if portions are needed
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { SlopDB, CheckCache } from "../scripts/indexed-db.js"
|
import { SlopDB, CheckCache } from "../scripts/indexed-db.js"
|
||||||
import { openDB, deleteDB } from "../scripts/idb/index.js"
|
import { openDB, deleteDB } from "../scripts/idb/index.js"
|
||||||
|
|
||||||
|
const MAX_TIMESTAMP_DIFFERENCE = 3
|
||||||
|
|
||||||
describe("sanity check", () => {
|
describe("sanity check", () => {
|
||||||
it("works", () => {
|
it("works", () => {
|
||||||
expect(true).toBeTrue()
|
expect(true).toBeTrue()
|
||||||
@@ -58,13 +60,16 @@ describe("SlopDB", () => {
|
|||||||
|
|
||||||
const slop_url = new URL("https://sloppy-slop.com/sloparticle")
|
const slop_url = new URL("https://sloppy-slop.com/sloparticle")
|
||||||
|
|
||||||
await cache.store(slop_url.host)
|
await cache.store(slop_url.toString())
|
||||||
const store_time = Date.now()
|
const store_time = Date.now()
|
||||||
const cached_item = cache.get(slop_url.host)
|
const cached_item = await cache.get(slop_url.toString())
|
||||||
|
|
||||||
expect(cached_item.url).toEqual(slop_url)
|
expect(cached_item.url).toEqual(slop_url.toString())
|
||||||
expect(cached_item.check_timestamp).toBeCloseTo(store_time)
|
expect(cached_item.check_timestamp).toBeLessThanOrEqual(store_time)
|
||||||
|
expect(cached_item.check_timestamp).toBeGreaterThan(store_time - MAX_TIMESTAMP_DIFFERENCE)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("updates a cached url's timestamp when it is accessed")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export class CheckCache {
|
|||||||
this.cache_capacity = max_entries
|
this.cache_capacity = max_entries
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_item_factory(url: URL) {
|
cache_item_factory(url: string) {
|
||||||
return {
|
return {
|
||||||
url: url,
|
url: url,
|
||||||
check_timestamp: Date.now()
|
check_timestamp: Date.now()
|
||||||
@@ -53,11 +53,12 @@ export class CheckCache {
|
|||||||
|
|
||||||
async store(url: string) {
|
async store(url: string) {
|
||||||
const cache_store = this.slopdb.db.transaction(CheckCache.cache_objectstore_name, "readwrite").objectStore(CheckCache.cache_objectstore_name)
|
const cache_store = this.slopdb.db.transaction(CheckCache.cache_objectstore_name, "readwrite").objectStore(CheckCache.cache_objectstore_name)
|
||||||
await cache_store.add(this.cache_item_factory(new URL(url)))
|
await cache_store.add(this.cache_item_factory(url))
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url: URL) {
|
async get(url: string) {
|
||||||
return url
|
const cache_store = this.slopdb.db.transaction(CheckCache.cache_objectstore_name, "readwrite").objectStore(CheckCache.cache_objectstore_name)
|
||||||
|
return cache_store.get(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
// async evict_least_recently_checked(count: number) {
|
// async evict_least_recently_checked(count: number) {
|
||||||
@@ -102,7 +103,7 @@ export class SlopDB {
|
|||||||
db.createObjectStore("slop", { keyPath: "domain" })
|
db.createObjectStore("slop", { keyPath: "domain" })
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
db.createObjectStore("checkcache", { keyPath: "domain" })
|
db.createObjectStore("checkcache", { keyPath: "url" })
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user