Clean up cache, add missing FK option

This commit is contained in:
Bryan Ashby 2023-01-28 12:59:12 -07:00
parent 6dd9fe810f
commit 0ca67f6729
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
2 changed files with 14 additions and 34 deletions

View File

@ -210,7 +210,7 @@ module.exports = class Actor extends ActivityPubObject {
static _fromCache(id, cb) {
apDb.get(
`SELECT actor_json, subject, timestamp
`SELECT rowid, actor_json, subject, timestamp,
FROM actor_cache
WHERE actor_id = ? OR subject = ?
LIMIT 1;`,
@ -226,8 +226,17 @@ module.exports = class Actor extends ActivityPubObject {
const timestamp = moment(row.timestamp);
if (moment().isAfter(timestamp.add(ActorCacheTTL))) {
// :TODO: drop from cache
return cb(Errors.Expired('The cache entry is expired'));
apDb.run(
`DELETE FROM actor_cache
WHERE rowid = ?;`,
[row.rowid],
err => {
if (err) {
// :TODO: Log me
}
return cb(Errors.Expired('The cache entry is expired'));
}
);
}
const obj = ActivityPubObject.fromJsonString(row.actor_json);

View File

@ -242,37 +242,6 @@ const DB_INIT_TABLE = {
return cb(null);
},
// actor: cb => {
// enableForeignKeys(dbs.actor);
// dbs.actor.run(
// `CREATE TABLE IF NOT EXISTS activitypub_actor (
// id INTEGER PRIMARY KEY,
// actor_url VARCHAR NOT NULL,
// UNIQUE(actor_url)
// );`
// );
// // :TODO: create FK on delete/etc.
// dbs.actor.run(
// `CREATE TABLE IF NOT EXISTS activitypub_actor_property (
// actor_id INTEGER NOT NULL,
// prop_name VARCHAR NOT NULL,
// prop_value VARCHAR,
// UNIQUE(actor_id, prop_name),
// FOREIGN KEY(actor_id) REFERENCES actor(id) ON DELETE CASCADE
// );`
// );
// dbs.actor.run(
// `CREATE INDEX IF NOT EXISTS activitypub_actor_property_id_and_name_index0
// ON activitypub_actor_property (actor_id, prop_name);`
// );
// return cb(null);
// },
message: cb => {
enableForeignKeys(dbs.message);
@ -502,6 +471,8 @@ dbs.message.run(
return cb(null);
},
activitypub: cb => {
enableForeignKeys(dbs.activitypub);
// Actors we know about and have cached
dbs.activitypub.run(
`CREATE TABLE IF NOT EXISTS actor_cache (