Skip to content

Commit 6c18502

Browse files
committed
limit concurrency when busting orchestrator model cache
1 parent 311b59a commit 6c18502

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed
+21-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { getResource, invalidateResource } from '@civitai/client';
2+
import { chunk } from 'lodash-es';
23
import { z } from 'zod';
34
import { getModelByAirSchema } from '~/server/schema/orchestrator/models.schema';
45
import { resourceDataCache } from '~/server/services/model-version.service';
56
import {
67
createOrchestratorClient,
78
internalOrchestratorClient,
89
} from '~/server/services/orchestrator/common';
10+
import { limitConcurrency } from '~/server/utils/concurrency-helpers';
911
import { stringifyAIR } from '~/utils/string-helpers';
1012

1113
export async function getModel({
@@ -22,20 +24,24 @@ export async function bustOrchestratorModelCache(versionIds: number | number[],
2224
const resources = await resourceDataCache.fetch(versionIds);
2325
if (!resources.length) return;
2426

25-
await Promise.all(
26-
resources.map(async (resource) => {
27-
const air = stringifyAIR({
28-
baseModel: resource.baseModel,
29-
type: resource.model.type,
30-
modelId: resource.model.id,
31-
id: resource.id,
32-
});
27+
const tasks = chunk(resources, 100).map((chunk) => async () => {
28+
await Promise.all(
29+
chunk.map(async (resource) => {
30+
const air = stringifyAIR({
31+
baseModel: resource.baseModel,
32+
type: resource.model.type,
33+
modelId: resource.model.id,
34+
id: resource.id,
35+
});
3336

34-
await invalidateResource({
35-
client: internalOrchestratorClient,
36-
path: { air },
37-
query: userId ? { userId: [userId] } : undefined,
38-
});
39-
})
40-
);
37+
await invalidateResource({
38+
client: internalOrchestratorClient,
39+
path: { air },
40+
query: userId ? { userId: [userId] } : undefined,
41+
});
42+
})
43+
);
44+
});
45+
46+
await limitConcurrency(tasks, 3);
4147
}

0 commit comments

Comments
 (0)