@@ -2,12 +2,12 @@ import { client } from '@workduck-io/dwindle'
2
2
3
3
import {
4
4
apiURLs ,
5
+ batchArray ,
5
6
defaultContent ,
6
7
DEFAULT_NAMESPACE ,
7
8
extractMetadata ,
8
9
getTagsFromContent ,
9
10
GET_REQUEST_MINIMUM_GAP ,
10
- iLinksToUpdate ,
11
11
mog ,
12
12
NodeEditorContent ,
13
13
removeNulls
@@ -26,7 +26,6 @@ import { useInternalLinks } from '../useInternalLinks'
26
26
import { useLastOpened } from '../useLastOpened'
27
27
import { useLinks } from '../useLinks'
28
28
import { useNodes } from '../useNodes'
29
- import { useSearch } from '../useSearch'
30
29
import { useSnippets } from '../useSnippets'
31
30
import { useUpdater } from '../useUpdater'
32
31
import { useAPIHeaders } from './useAPIHeaders'
@@ -376,33 +375,35 @@ export const useApi = () => {
376
375
return newSnippets
377
376
} )
378
377
. then ( async ( newSnippets ) => {
379
- const ids = newSnippets ?. map ( ( item ) => item . snippetID )
380
- mog ( 'NewSnippets' , { newSnippets, ids } )
381
-
382
- if ( ids && ids . length > 0 ) {
383
- const res = await runBatchWorker ( WorkerRequestType . GET_SNIPPETS , 6 , ids )
384
- const requestData = { time : Date . now ( ) , method : 'GET' }
385
-
386
- res . fulfilled . forEach ( async ( snippet ) => {
387
- setRequest ( apiURLs . snippet . getSnippetById ( snippet . id ) , {
388
- ...requestData ,
389
- url : apiURLs . snippet . getSnippetById ( snippet . id )
378
+ const toUpdateSnippets = newSnippets ?. map ( ( item ) => item . snippetID )
379
+ mog ( 'NewSnippets' , { newSnippets, toUpdateSnippets } )
380
+ if ( toUpdateSnippets && toUpdateSnippets . length > 0 ) {
381
+ const ids = batchArray ( toUpdateSnippets , 10 ) . map ( ( id : string [ ] ) => id . join ( ',' ) )
382
+ if ( ids && ids . length > 0 ) {
383
+ const res = await runBatchWorker ( WorkerRequestType . GET_SNIPPETS , 6 , ids )
384
+ const requestData = { time : Date . now ( ) , method : 'GET' }
385
+
386
+ res . fulfilled . forEach ( async ( snippets ) => {
387
+ setRequest ( apiURLs . snippet . bulkGet , {
388
+ ...requestData ,
389
+ url : apiURLs . snippet . bulkGet
390
+ } )
391
+
392
+ if ( snippets ) {
393
+ snippets . forEach ( ( snippet ) => updateSnippet ( snippet ) )
394
+ }
390
395
} )
391
396
392
- if ( snippet ) {
393
- updateSnippet ( snippet )
394
- }
395
- } )
396
-
397
- mog ( 'RunBatchWorkerSnippetsRes' , { res, ids } )
397
+ mog ( 'RunBatchWorkerSnippetsRes' , { res, ids } )
398
+ }
398
399
}
399
400
} )
400
401
401
402
return data
402
403
}
403
404
404
- const getSnippetById = async ( id : string ) => {
405
- const url = apiURLs . snippet . getSnippetById ( id )
405
+ const getById = async ( id : string ) => {
406
+ const url = apiURLs . snippet . getById ( id )
406
407
407
408
const data = await client
408
409
. get ( url , {
@@ -467,7 +468,7 @@ export const useApi = () => {
467
468
appendToNode,
468
469
saveSnippetAPI,
469
470
getAllSnippetsByWorkspace,
470
- getSnippetById ,
471
+ getById ,
471
472
refactorHierarchy,
472
473
deleteAllVersionOfSnippet
473
474
}
0 commit comments