Updating Manticore scenes database on scene store.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user