perf: set patrons in redis
This commit is contained in:
parent
344adbe2a1
commit
c5d102021e
|
@ -1,5 +1,5 @@
|
||||||
import define from "../define.js";
|
import define from "../define.js";
|
||||||
import Logger from "@/services/logger.js";
|
import { redisClient } from "@/db/redis.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ["meta"],
|
tags: ["meta"],
|
||||||
|
@ -17,16 +17,16 @@ export const paramDef = {
|
||||||
|
|
||||||
export default define(meta, paramDef, async () => {
|
export default define(meta, paramDef, async () => {
|
||||||
let patrons;
|
let patrons;
|
||||||
await fetch(
|
const cachedPatrons = await redisClient.get("patrons");
|
||||||
"https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json",
|
if (cachedPatrons) {
|
||||||
)
|
patrons = JSON.parse(cachedPatrons);
|
||||||
.then((response) => response.json())
|
}
|
||||||
.then((data) => {
|
else {
|
||||||
patrons = data["patrons"];
|
patrons = await fetch(
|
||||||
})
|
"https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json",
|
||||||
.catch((error) => {
|
).then((response) => response.json());
|
||||||
console.error("Error fetching patrons:", error);
|
await redisClient.set("patrons", JSON.stringify(patrons), "EX", 3600);
|
||||||
});
|
}
|
||||||
|
|
||||||
return patrons;
|
return patrons["patrons"];
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue