Updating Manticore scenes database on scene store.

This commit is contained in:
DebaucheryLibrarian
2024-01-25 01:15:42 +01:00
parent ae2d3591ee
commit 86ffcc3316
31 changed files with 237 additions and 27 deletions

View File

@@ -1,8 +1,13 @@
'use strict';
const config = require('config');
const knex = require('./knex');
const { HttpError } = require('./errors');
const slugify = require('./utils/slugify');
const logger = require('./logger')(__filename);
let lastActorsViewRefresh = 0;
function curateStash(stash) {
if (!stash) {
@@ -119,6 +124,21 @@ async function removeStash(stashId, sessionUser) {
}
}
async function refreshActorsView() {
if (new Date() - lastActorsViewRefresh > config.stashes.viewRefreshCooldown * 60000) {
// don't refresh actors view more than once an hour
lastActorsViewRefresh = new Date();
logger.debug('Refreshing actors view');
return knex.schema.refreshMaterializedView('actors_meta');
}
logger.silly('Skipping actors view refresh');
return false;
}
async function stashActor(actorId, stashId, sessionUser) {
const stash = await fetchStash(stashId, sessionUser);
@@ -128,6 +148,8 @@ async function stashActor(actorId, stashId, sessionUser) {
actor_id: actorId,
});
refreshActorsView();
return fetchStashes('actor', actorId, sessionUser);
}
@@ -166,6 +188,8 @@ async function unstashActor(actorId, stashId, sessionUser) {
.where('stashes.user_id', sessionUser.id))
.delete();
refreshActorsView();
return fetchStashes('actor', actorId, sessionUser);
}