@@ -345,18 +345,26 @@ export class BitbucketServerApi {
345
345
} ;
346
346
347
347
if ( query . searchString ?. trim ( ) ) {
348
- const result : BitbucketServer . Repository [ ] = [ ] ;
349
- const ids = new Set < number > ( ) ; // used to deduplicate
350
- for ( const param of [ "name" , "projectname" ] ) {
351
- const pageResult = await runQuery ( `${ param } =${ query . searchString } ` ) ;
352
- for ( const repo of pageResult ) {
353
- if ( ! ids . has ( repo . id ) ) {
354
- ids . add ( repo . id ) ;
355
- result . push ( repo ) ;
356
- }
357
- }
348
+ const results : Map < number , BitbucketServer . Repository > = new Map ( ) ;
349
+
350
+ // Query by name & projectname in parrallel
351
+ const [ nameResults , projectResults ] = await Promise . all ( [
352
+ runQuery ( `name=${ query . searchString } ` ) ,
353
+ runQuery ( `projectname=${ query . searchString } ` ) ,
354
+ ] ) ;
355
+ for ( const repo of [ ...nameResults , ...projectResults ] ) {
356
+ results . set ( repo . id , repo ) ;
358
357
}
359
- return result ;
358
+
359
+ return Array . from ( results . values ( ) ) ;
360
+ } else if ( query . searchString ?. trim ( ) === "" && ( query . limit || query . cap ) ) {
361
+ // Empty search w/ limit/cap set - just grab latest repos
362
+ const { values = [ ] } = await this . runQuery < BitbucketServer . Paginated < BitbucketServer . Repository > > (
363
+ userOrToken ,
364
+ `/profile/recent/repos?${ permission } ${ limit } ` ,
365
+ ) ;
366
+
367
+ return values ;
360
368
} else {
361
369
return await runQuery ( `limit=1000` ) ;
362
370
}
0 commit comments