Skip to content

Commit f34e869

Browse files
committed
✨ cache sharedGuilds response for 30 minutes
1 parent 6579b9b commit f34e869

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/app/lib/realm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import lscache from "lscache";
2-
import DiscordClient from "./discord";
2+
import DiscordClient, { NamedThing } from "./discord";
33

44
const realmApi = import.meta.env.VITE_APP_REALM_API;
55

@@ -86,7 +86,7 @@ export default class RealmClient {
8686
});
8787
}
8888

89-
async getSharedGuilds() {
89+
async getSharedGuilds(): Promise<NamedThing[]> {
9090
return await this.realmApi("/auth/shared-guilds")
9191
.then((r) => r.json())
9292
.then((d) => d.guilds);

src/app/views/main.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
import DiscordAvatar from "@/app/components/discord-avatar.vue";
33
import { doneLoading } from "@/app/lib/global";
44
import RealmClient from "@/app/lib/realm";
5+
import lscache from "lscache";
56
import { inject, onMounted } from "vue";
7+
import { NamedThing } from "../lib/discord";
68
79
const realm: RealmClient = inject("realmClient")!;
8-
const sharedGuilds = await realm.getSharedGuilds();
10+
lscache.setBucket("requests");
11+
let sharedGuilds: NamedThing[] | null = lscache.get("sharedGuilds");
12+
13+
if (!sharedGuilds) {
14+
sharedGuilds = await realm.getSharedGuilds();
15+
lscache.set("sharedGuilds", sharedGuilds, 30);
16+
}
917
1018
onMounted(() => doneLoading());
1119
</script>

0 commit comments

Comments
 (0)