This commit is contained in:
eric
2026-03-26 11:32:13 -05:00
parent 8c865cf0e8
commit f5068c0ead
3 changed files with 40 additions and 1 deletions

View File

@@ -15,6 +15,8 @@ type PayjsVipResult = {
email?: string;
};
const inflightUserChecks = new Map<string, Promise<PayjsVipResult | null>>();
async function fetchPayjsVipWithRetry(
url: string,
timeoutMs: number,
@@ -51,6 +53,12 @@ async function checkVipFromPayjsapi(
request: NextRequest,
userId: string
): Promise<PayjsVipResult | null> {
const existed = inflightUserChecks.get(userId);
if (existed) {
return existed;
}
const task = (async () => {
try {
const apiUrl = resolvePayApiUrl(request);
const url = `${apiUrl}/nomadvip/check_vip?user_id=${encodeURIComponent(
@@ -95,6 +103,14 @@ async function checkVipFromPayjsapi(
);
return null;
}
})();
inflightUserChecks.set(userId, task);
try {
return await task;
} finally {
inflightUserChecks.delete(userId);
}
}
export async function POST(request: NextRequest) {