Skip to content

Commit

Permalink
Improve safety of cache entry
Browse files Browse the repository at this point in the history
It seems a comment can have a lower timestamp than the submission? This
is strange because it would point to inconsistencies in the storage
algorithm.

In any case, considering this could also be a local artifact, it is
important to just have that part of the re-creation algorithm of the
cache fail while the rest continues to run.
  • Loading branch information
TimDaub committed Jul 4, 2024
1 parent e587729 commit a9236e3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Database from "better-sqlite3";
import { add } from "date-fns";
import normalizeUrl from "normalize-url";

import log from "./logger.mjs";

const dbPath = join(process.env.CACHE_DIR, "database.db");
const db = new Database(dbPath);
db.pragma("journal_mode = WAL");
Expand Down Expand Up @@ -556,14 +558,18 @@ function insertMessage(message) {
const insertComment = db.prepare(
`INSERT INTO comments (id, submission_id, timestamp, title, signer, identity) VALUES (?, ?, ?, ?, ?, ?)`,
);
insertComment.run(
`kiwi:0x${index}`,
href,
timestamp,
title,
signer,
identity,
);
try {
insertComment.run(
`kiwi:0x${index}`,
href,
timestamp,
title,
signer,
identity,
);
} catch (err) {
log(`Failing to insert comment "${title}", error: "${err.toString()}"`);
}
} else {
throw new Error("Unsupported message type");
}
Expand Down

0 comments on commit a9236e3

Please sign in to comment.