's'
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user