summaryrefslogtreecommitdiff
path: root/src/queue
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-03-18 10:49:14 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-03-18 10:52:54 +0900
commit8aa089178a54559cbc4e4fe84a618fc7535f178c (patch)
tree5f8cb6d5c51a37f4b667f7cd76d836f500cee1b4 /src/queue
parentImprove API performance (diff)
downloadsharkey-8aa089178a54559cbc4e4fe84a618fc7535f178c.tar.gz
sharkey-8aa089178a54559cbc4e4fe84a618fc7535f178c.tar.bz2
sharkey-8aa089178a54559cbc4e4fe84a618fc7535f178c.zip
Improve server performance
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/processors/deliver.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/queue/processors/deliver.ts b/src/queue/processors/deliver.ts
index cb7587ef81..a8b4ed4fe3 100644
--- a/src/queue/processors/deliver.ts
+++ b/src/queue/processors/deliver.ts
@@ -7,11 +7,15 @@ import { instanceChart } from '../../services/chart';
import { fetchInstanceMetadata } from '../../services/fetch-instance-metadata';
import { fetchMeta } from '../../misc/fetch-meta';
import { toPuny } from '../../misc/convert-host';
+import { Cache } from '../../misc/cache';
+import { Instance } from '../../models/entities/instance';
const logger = new Logger('deliver');
let latest: string | null = null;
+const suspendedHostsCache = new Cache<Instance[]>(1000 * 60 * 60);
+
export default async (job: Bull.Job) => {
const { host } = new URL(job.data.to);
@@ -22,12 +26,15 @@ export default async (job: Bull.Job) => {
}
// isSuspendedなら中断
- const suspendedHosts = await Instances.find({
- where: {
- isSuspended: true
- },
- cache: 60 * 1000
- });
+ let suspendedHosts = suspendedHostsCache.get(null);
+ if (suspendedHosts == null) {
+ suspendedHosts = await Instances.find({
+ where: {
+ isSuspended: true
+ },
+ });
+ suspendedHostsCache.set(null, suspendedHosts);
+ }
if (suspendedHosts.map(x => x.host).includes(toPuny(host))) {
return 'skip (suspended)';
}