Skip to content

Commit

Permalink
Reduce async/await context
Browse files Browse the repository at this point in the history
  • Loading branch information
mzyy94 committed May 25, 2024
1 parent 6c86ef7 commit 4d60c26
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/api/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const registerAccount = factory.createHandlers(
target: users.user,
set: { handle: identifier, issuedAt: now },
});
await savePubkey(c, didDoc.id, findPubkey(didDoc) ?? '');
savePubkey(c, didDoc.id, findPubkey(didDoc) ?? '');

const { JWT_SECRET } = env<{ JWT_SECRET: string }>(c);
const token = await sign(
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const XrpcAuth = (opt: Option) =>
if (!verified) {
throw authError(c, 401, 'unauthorized', 'token verification failure');
}
await savePubkey(c, iss, pubkey);
savePubkey(c, iss, pubkey);
}

c.set('iss', iss);
Expand Down
8 changes: 4 additions & 4 deletions src/pubkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export function findPubkey(didDoc: DidDoc): string | null {
return null;
}

export async function savePubkey(c: Context, did: string, pubkey: string) {
export function savePubkey(c: Context, did: string, pubkey: string) {
if (!did || !pubkey) {
return;
}
await putPubkeyToCache(did, pubkey);
c.executionCtx.waitUntil(putPubkeyToCache(did, pubkey));
const { did_key_store } = env<{ did_key_store: KVNamespace }>(c);
await did_key_store.put(did, pubkey);
c.executionCtx.waitUntil(did_key_store.put(did, pubkey));
}

export async function getPubkey(c: Context, did: string) {
Expand All @@ -31,7 +31,7 @@ export async function getPubkey(c: Context, did: string) {
}
pubkey = await did_key_store.get(did);
if (pubkey) {
await putPubkeyToCache(did, pubkey);
c.executionCtx.waitUntil(putPubkeyToCache(did, pubkey));
}
return pubkey;
}
Expand Down
4 changes: 3 additions & 1 deletion src/xrpc/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ export const getFeedSkeletonHandlers = factory.createHandlers(
const feed = result.map(({ post }) => ({ post }));
const lastPost = result.at(-1);
const lastCur = createCursor(lastPost);
await putFeedToCache(c, user, feedItems, opId, range, !cursor);
c.executionCtx.waitUntil(
putFeedToCache(c, user, feedItems, opId, range, !cursor),
);

return c.json<TFeed, 200>({ cursor: lastCur, feed });
},
Expand Down

0 comments on commit 4d60c26

Please sign in to comment.