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");
|
||||||
|
if (cachedPatrons) {
|
||||||
|
patrons = JSON.parse(cachedPatrons);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
patrons = await fetch(
|
||||||
"https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json",
|
"https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json",
|
||||||
)
|
).then((response) => response.json());
|
||||||
.then((response) => response.json())
|
await redisClient.set("patrons", JSON.stringify(patrons), "EX", 3600);
|
||||||
.then((data) => {
|
}
|
||||||
patrons = data["patrons"];
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Error fetching patrons:", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
return patrons;
|
return patrons["patrons"];
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue