Skip to content

Commit

Permalink
Make allowlist and delegations cached
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Feb 3, 2025
1 parent af1c030 commit 5091576
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ export function listAllowed(getAllowlist) {
}
}

if (request.query.cached === "true") {
reply.header(
"Cache-Control",
"public, s-maxage=1, max-age=1, stale-while-revalidate=1",
);
}

const code = 200;
const httpMessage = "OK";
const details = "Returning allow list";
Expand All @@ -165,6 +172,13 @@ export function listAllowed(getAllowlist) {

export function listDelegations(getDelegations) {
return async (request, reply) => {
if (request.query.cached === "true") {
reply.header(
"Cache-Control",
"public, s-maxage=1, max-age=1, stale-while-revalidate=1",
);
}

const code = 200;
const httpMessage = "OK";
const details = "Returning delegations list";
Expand Down
10 changes: 6 additions & 4 deletions src/web/src/API.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ export async function fetchKarma(identity) {
}
}

export async function fetchDelegations() {
const url = getApiUrl("/api/v1/delegations", API_PORT);
export async function fetchDelegations(cached = false) {
const url = new URL(getApiUrl("/api/v1/delegations", API_PORT));
if (cached) url.searchParams.set("cached", "true");

let response;
try {
Expand All @@ -236,8 +237,9 @@ export async function fetchDelegations() {
}
}

export async function fetchAllowList() {
const url = getApiUrl("/api/v1/allowlist", API_PORT);
export async function fetchAllowList(cached = false) {
const url = new URL(getApiUrl("/api/v1/allowlist", API_PORT));
if (cached) url.searchParams.set("cached", "true");

let response;
try {
Expand Down
5 changes: 3 additions & 2 deletions src/web/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,9 @@ async function start() {

const { fetchAllowList, fetchDelegations } = await import("./API.mjs");

const allowlistPromise = fetchAllowList();
const delegationsPromise = fetchDelegations();
const cached = true;
const allowlistPromise = fetchAllowList(cached);
const delegationsPromise = fetchDelegations(cached);

await startWatchAccount(await allowlistPromise, await delegationsPromise);

Expand Down

0 comments on commit 5091576

Please sign in to comment.