@@ -607,14 +607,6 @@ function originOf(value: string): string | null {
607607 }
608608}
609609
610- function hostOf ( value : string ) : string | null {
611- try {
612- return new URL ( value ) . host ;
613- } catch {
614- return null ;
615- }
616- }
617-
618610const responseError = Effect . fn ( "BitbucketApi.responseError" ) ( function * (
619611 operation : BitbucketApiOperation ,
620612 response : HttpClientResponse . HttpClientResponse ,
@@ -652,9 +644,10 @@ export const make = Effect.gen(function* () {
652644 const fileSystem = yield * FileSystem . FileSystem ;
653645 const limits = yield * SourceControlRateLimit . SourceControlRateLimit ;
654646 const slots = yield * Semaphore . make ( CONCURRENCY ) ;
647+ // The repository host PullRequestService keys its own backoff under, so both share one pause.
655648 const rateLimitKey = {
656649 provider : SourceControlProviderKind . make ( "bitbucket" ) ,
657- host : hostOf ( config . baseUrl ) ?? config . baseUrl ,
650+ host : "bitbucket.org" ,
658651 } ;
659652
660653 const apiUrl = ( path : string ) => `${ config . baseUrl . replace ( / \/ + $ / u, "" ) } ${ path } ` ;
@@ -698,32 +691,26 @@ export const make = Effect.gen(function* () {
698691 * Background reads fail at once while paused; a write or an interactive read has a user waiting
699692 * on it, so it still goes out.
700693 */
701- const throttled = < A , R > (
702- method : string ,
703- effect : Effect . Effect < A , BitbucketApiError , R > ,
704- ) : Effect . Effect < A , BitbucketApiError , R > =>
705- slots . withPermit (
706- SourceControlRateLimit . Interactive . pipe (
707- Effect . flatMap ( ( interactive ) =>
708- limits . check (
709- rateLimitKey ,
710- interactive || method !== "GET" ? { allowPaused : true } : undefined ,
711- ) ,
712- ) ,
713- Effect . flatMap ( ( lease ) =>
714- effect . pipe (
715- Effect . tap ( ( ) => limits . recordSuccess ( { ...rateLimitKey , lease } ) ) ,
716- Effect . tapError ( ( error ) =>
717- ( error . _tag === "BitbucketResponseError" ||
718- error . _tag === "BitbucketResponseBodyReadError" ) &&
719- error . status === 429
720- ? limits . recordRateLimit ( { ...rateLimitKey , lease, retryAt : error . retryAt } )
721- : Effect . void ,
722- ) ,
723- ) ,
694+ const throttled = Effect . fn ( "BitbucketApi.throttled" ) (
695+ function * < A , R > ( method : string , effect : Effect . Effect < A , BitbucketApiError , R > ) {
696+ const interactive = yield * SourceControlRateLimit . Interactive ;
697+ const lease = yield * limits . check (
698+ rateLimitKey ,
699+ interactive || method !== "GET" ? { allowPaused : true } : undefined ,
700+ ) ;
701+ return yield * effect . pipe (
702+ Effect . tap ( ( ) => limits . recordSuccess ( { ...rateLimitKey , lease } ) ) ,
703+ Effect . tapError ( ( error ) =>
704+ ( error . _tag === "BitbucketResponseError" ||
705+ error . _tag === "BitbucketResponseBodyReadError" ) &&
706+ error . status === 429
707+ ? limits . recordRateLimit ( { ...rateLimitKey , lease, retryAt : error . retryAt } )
708+ : Effect . void ,
724709 ) ,
725- ) ,
726- ) ;
710+ ) ;
711+ } ,
712+ ( effect ) => slots . withPermit ( effect ) ,
713+ ) ;
727714
728715 const decodeResponse = < S extends Schema . Top > (
729716 operation : BitbucketApiOperation ,
0 commit comments