Added cache reload button to admin panel so restarts are needed less often.
This commit is contained in:
10
src/app.js
10
src/app.js
@@ -1,14 +1,8 @@
|
||||
import initServer from './web/server.js';
|
||||
import { cacheTagIds } from './tags.js';
|
||||
import { cacheEntityIds } from './entities.js';
|
||||
import { cacheCampaigns } from './campaigns.js';
|
||||
import { initCaches } from './cache.js';
|
||||
|
||||
async function init() {
|
||||
await Promise.all([
|
||||
cacheTagIds(),
|
||||
cacheEntityIds(),
|
||||
cacheCampaigns(),
|
||||
]);
|
||||
await initCaches();
|
||||
|
||||
initServer();
|
||||
}
|
||||
|
||||
12
src/cache.js
12
src/cache.js
@@ -1,5 +1,9 @@
|
||||
import redis from './redis.js';
|
||||
|
||||
import { cacheTagIds } from './tags.js';
|
||||
import { cacheEntityIds } from './entities.js';
|
||||
import { cacheCampaigns } from './campaigns.js';
|
||||
|
||||
export async function getIdsBySlug(slugs, domain, toMap) {
|
||||
if (!slugs) {
|
||||
return [];
|
||||
@@ -25,3 +29,11 @@ export async function getIdsBySlug(slugs, domain, toMap) {
|
||||
|
||||
return ids.filter(Boolean);
|
||||
}
|
||||
|
||||
export async function initCaches() {
|
||||
await Promise.all([
|
||||
cacheTagIds(),
|
||||
cacheEntityIds(),
|
||||
cacheCampaigns(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export default async function initRestrictionHandler() {
|
||||
const reader = await Reader.open('assets/GeoLite2-City.mmdb');
|
||||
|
||||
function getRestriction(req) {
|
||||
if (req.session.restriction && req.session.country && req.session.restrictionIp === req.userIp) {
|
||||
if (Object.hasOwn(req.session, 'restriction') && Object.hasOwn(req.session, 'country') && req.session.restrictionIp === req.userIp) {
|
||||
return {
|
||||
restriction: req.session.restriction,
|
||||
country: req.session.country,
|
||||
@@ -71,6 +71,10 @@ export default async function initRestrictionHandler() {
|
||||
req.country = country;
|
||||
} catch (error) {
|
||||
logger.error(`Failed Maxmind IP lookup for ${req.ip}: ${error.message}`);
|
||||
|
||||
req.session.restrictionIp = req.userIp;
|
||||
req.session.restriction = 0;
|
||||
req.session.country = null;
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
@@ -41,6 +41,8 @@ import { router as userRouter } from './users.js';
|
||||
import { router as stashesRouter } from './stashes.js';
|
||||
import { router as alertsRouter } from './alerts.js';
|
||||
|
||||
import { initCachesApi } from './system.js';
|
||||
|
||||
import initLogger from '../logger.js';
|
||||
|
||||
const logger = initLogger();
|
||||
@@ -158,6 +160,8 @@ export default async function initServer() {
|
||||
// TAGS
|
||||
router.get('/api/tags', fetchTagsApi);
|
||||
|
||||
router.post('/api/caches', initCachesApi);
|
||||
|
||||
if (config.apiAccess.graphqlEnabled) {
|
||||
router.post('/graphql', graphqlApi);
|
||||
}
|
||||
|
||||
12
src/web/system.js
Normal file
12
src/web/system.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { HttpError } from '../errors.js';
|
||||
import { initCaches } from '../cache.js';
|
||||
|
||||
export async function initCachesApi(req, res) {
|
||||
if (req.user?.role !== 'admin') {
|
||||
throw new HttpError('You must be an admin to initialize caches', 404);
|
||||
}
|
||||
|
||||
await initCaches();
|
||||
|
||||
res.status(204).send();
|
||||
}
|
||||
Reference in New Issue
Block a user