更新处理这个外观部分

This commit is contained in:
super
2026-05-01 00:09:14 +08:00
parent 668226a99d
commit 70658041a5
9 changed files with 411 additions and 69 deletions

View File

@@ -15,6 +15,10 @@ type TaskProgressCacheEntry = {
data: unknown;
};
interface TaskProgressBatchOptions {
force?: boolean;
}
const taskProgressResponseCache = new Map<string, TaskProgressCacheEntry>();
const taskProgressInflightRequests = new Map<string, Promise<unknown>>();
@@ -44,7 +48,11 @@ function buildTaskProgressRequestKey(path: string, taskIds: number[]) {
return `${path}::${taskIds.join(",")}`;
}
async function postTaskProgressBatch<T>(path: string, taskIds: number[]) {
async function postTaskProgressBatch<T>(
path: string,
taskIds: number[],
options: TaskProgressBatchOptions = {},
) {
const normalizedTaskIds = normalizeTaskIds(taskIds);
if (!normalizedTaskIds.length) {
return { items: [], missingTaskIds: [] } as T;
@@ -53,12 +61,12 @@ async function postTaskProgressBatch<T>(path: string, taskIds: number[]) {
const cacheKey = buildTaskProgressRequestKey(path, normalizedTaskIds);
const now = Date.now();
const cached = taskProgressResponseCache.get(cacheKey);
if (cached && cached.expiresAt > now) {
if (!options.force && cached && cached.expiresAt > now) {
return cached.data as T;
}
const inflight = taskProgressInflightRequests.get(cacheKey);
if (inflight) {
if (!options.force && inflight) {
return (await inflight) as T;
}
@@ -1500,15 +1508,19 @@ export function getAppearancePatentHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<AppearancePatentHistoryVo>>(
`${JAVA_API_PREFIX}/appearance-patent/history`,
{ params: { user_id: getCurrentUserId() } },
{ params: { user_id: getCurrentUserId(), limit: 50 } },
),
);
}
export function getAppearancePatentTaskProgressBatch(taskIds: number[]) {
export function getAppearancePatentTaskProgressBatch(
taskIds: number[],
options: TaskProgressBatchOptions = {},
) {
return postTaskProgressBatch<AppearancePatentTaskBatchVo>(
`${JAVA_API_PREFIX}/appearance-patent/tasks/progress/batch`,
taskIds,
options,
);
}