perf: fetch patrons from local file
This commit is contained in:
parent
e04c6e7b85
commit
b82a7eae98
2 changed files with 5 additions and 28 deletions
|
@ -13,6 +13,8 @@
|
|||
|
||||
## 細かい変更点
|
||||
|
||||
- 支援者リストをファイルから読み込む
|
||||
- 外部のサーバーが落ちるとユーザーページが開けなくなることを防ぐため
|
||||
- 閲覧注意の注釈と画像の代替テキストもアンテナで調べる対象にする
|
||||
- ~~「そぎぎ」でアンテナを作れる~~
|
||||
- インデックス拒否に `noindex` に加えて `nofollow,noarchive,nocache,noimageindex` も指定
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import define from "../define.js";
|
||||
import { redisClient } from "@/db/redis.js";
|
||||
import * as fs from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname } from "node:path";
|
||||
|
@ -24,33 +23,9 @@ export const paramDef = {
|
|||
} as const;
|
||||
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
let patrons;
|
||||
const cachedPatrons = await redisClient.get("patrons");
|
||||
if (!ps.forceUpdate && cachedPatrons) {
|
||||
patrons = JSON.parse(cachedPatrons);
|
||||
} else {
|
||||
AbortSignal.timeout ??= function timeout(ms) {
|
||||
const ctrl = new AbortController();
|
||||
setTimeout(() => ctrl.abort(), ms);
|
||||
return ctrl.signal;
|
||||
};
|
||||
|
||||
patrons = await fetch(
|
||||
"https://gitlab.prometheus.systems/firefish/firefish/-/raw/develop/patrons.json",
|
||||
{ signal: AbortSignal.timeout(2000) },
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.catch(() => {
|
||||
const staticPatrons = JSON.parse(
|
||||
fs.readFileSync(
|
||||
`${_dirname}/../../../../../../patrons.json`,
|
||||
"utf-8",
|
||||
),
|
||||
);
|
||||
patrons = cachedPatrons ? JSON.parse(cachedPatrons) : staticPatrons;
|
||||
});
|
||||
await redisClient.set("patrons", JSON.stringify(patrons), "EX", 3600);
|
||||
}
|
||||
const patrons = JSON.parse(
|
||||
fs.readFileSync(`${_dirname}/../../../../../../patrons.json`, "utf-8"),
|
||||
);
|
||||
return {
|
||||
patrons: patrons["patrons"],
|
||||
sponsors: patrons["sponsors"],
|
||||
|
|
Loading…
Reference in a new issue