1
0
Fork 0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2026-03-22 12:21:37 +00:00

Preserve history error kind

This commit is contained in:
Cadence Ember 2021-01-30 19:40:20 +13:00
parent 2419fbf08b
commit 5ed035a432
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
2 changed files with 11 additions and 9 deletions

View file

@ -7,7 +7,7 @@ class RequestHistory {
*/
constructor(tracked) {
this.tracked = new Set(tracked)
/** @type {Map<string, {lastRequestAt: number | null, lastRequestSuccessful: boolean | null}>} */
/** @type {Map<string, {lastRequestAt: number | null, lastRequestSuccessful: boolean | null, kind?: any}>} */
this.store = new Map()
for (const key of tracked) {
this.store.set(key, {
@ -20,12 +20,14 @@ class RequestHistory {
/**
* @param {string} key
* @param {boolean} success
* @param {any} [kind]
*/
report(key, success) {
report(key, success, kind) {
if (!this.tracked.has(key)) throw new Error(`Trying to report key ${key}, but is not tracked`)
const entry = this.store.get(key)
entry.lastRequestAt = Date.now()
entry.lastRequestSuccessful = success
entry.kind = kind
if (constants.caching.db_request_history) {
db.prepare("INSERT INTO RequestHistory (type, success, timestamp) VALUES (?, ?, ?)").run(key, +entry.lastRequestSuccessful, entry.lastRequestAt)
}