perf: set patrons in redis

This commit is contained in:
ThatOneCalculator 2023-06-08 13:19:46 -07:00
parent 344adbe2a1
commit c5d102021e
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
1 changed files with 12 additions and 12 deletions

View File

@ -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"];
}); });