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) {
|
static _fromCache(id, cb) {
|
||||||
apDb.get(
|
apDb.get(
|
||||||
`SELECT actor_json, subject, timestamp
|
`SELECT rowid, actor_json, subject, timestamp,
|
||||||
FROM actor_cache
|
FROM actor_cache
|
||||||
WHERE actor_id = ? OR subject = ?
|
WHERE actor_id = ? OR subject = ?
|
||||||
LIMIT 1;`,
|
LIMIT 1;`,
|
||||||
|
@ -226,9 +226,18 @@ module.exports = class Actor extends ActivityPubObject {
|
||||||
|
|
||||||
const timestamp = moment(row.timestamp);
|
const timestamp = moment(row.timestamp);
|
||||||
if (moment().isAfter(timestamp.add(ActorCacheTTL))) {
|
if (moment().isAfter(timestamp.add(ActorCacheTTL))) {
|
||||||
// :TODO: drop from cache
|
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'));
|
return cb(Errors.Expired('The cache entry is expired'));
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const obj = ActivityPubObject.fromJsonString(row.actor_json);
|
const obj = ActivityPubObject.fromJsonString(row.actor_json);
|
||||||
if (!obj || !obj.isValid()) {
|
if (!obj || !obj.isValid()) {
|
||||||
|
|
|
@ -242,37 +242,6 @@ const DB_INIT_TABLE = {
|
||||||
|
|
||||||
return cb(null);
|
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 => {
|
message: cb => {
|
||||||
enableForeignKeys(dbs.message);
|
enableForeignKeys(dbs.message);
|
||||||
|
|
||||||
|
@ -502,6 +471,8 @@ dbs.message.run(
|
||||||
return cb(null);
|
return cb(null);
|
||||||
},
|
},
|
||||||
activitypub: cb => {
|
activitypub: cb => {
|
||||||
|
enableForeignKeys(dbs.activitypub);
|
||||||
|
|
||||||
// Actors we know about and have cached
|
// Actors we know about and have cached
|
||||||
dbs.activitypub.run(
|
dbs.activitypub.run(
|
||||||
`CREATE TABLE IF NOT EXISTS actor_cache (
|
`CREATE TABLE IF NOT EXISTS actor_cache (
|
||||||
|
|
Loading…
Reference in New Issue