1
1
import { getResource , invalidateResource } from '@civitai/client' ;
2
+ import { chunk } from 'lodash-es' ;
2
3
import { z } from 'zod' ;
3
4
import { getModelByAirSchema } from '~/server/schema/orchestrator/models.schema' ;
4
5
import { resourceDataCache } from '~/server/services/model-version.service' ;
5
6
import {
6
7
createOrchestratorClient ,
7
8
internalOrchestratorClient ,
8
9
} from '~/server/services/orchestrator/common' ;
10
+ import { limitConcurrency } from '~/server/utils/concurrency-helpers' ;
9
11
import { stringifyAIR } from '~/utils/string-helpers' ;
10
12
11
13
export async function getModel ( {
@@ -22,20 +24,24 @@ export async function bustOrchestratorModelCache(versionIds: number | number[],
22
24
const resources = await resourceDataCache . fetch ( versionIds ) ;
23
25
if ( ! resources . length ) return ;
24
26
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
+ } ) ;
33
36
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 ) ;
41
47
}
0 commit comments