Clean up cache, add missing FK option
This commit is contained in:
parent
6dd9fe810f
commit
0ca67f6729
|
@ -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);
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue