@@ -257,31 +257,15 @@ export const make = Effect.gen(function* () {
257257 return held ;
258258 } ;
259259
260- /**
261- * `az repos pr show`, shared by the reads of one pull request that overlap: a review opening asks
262- * for its detail, conversation and diff at once, and each of them can start here. Nothing is kept
263- * once it answers, so a read that starts afterwards asks Azure again.
264- */
265- const pullRequestReads = yield * Cache . makeWith (
266- ( key : string ) => {
267- const [ cwd = "" , number = "" ] = key . split ( "\n" ) . map ( decodeURIComponent ) ;
268- return cli
269- . getPullRequest ( { cwd, number : Number ( number ) } )
270- . pipe (
271- Effect . tap ( ( pullRequest ) =>
272- Effect . sync ( ( ) => rememberLocation ( cwd , pullRequest , { evict : true } ) ) ,
273- ) ,
274- ) ;
275- } ,
276- { capacity : LOCATION_CACHE_CAPACITY , timeToLive : ( ) => Duration . zero } ,
277- ) ;
278-
260+ // Each read uses the current CLI sign-in, including reads overlapping an account switch.
279261 const readPullRequest = ( input : { readonly cwd : string ; readonly number : number } ) =>
280- Cache . get ( pullRequestReads , cacheKey ( input . cwd , input . number ) ) ;
281-
282- /** Run after a write, so a read asked for once it lands cannot join one that started before. */
283- const forgetRead = ( input : { readonly cwd : string ; readonly number : number } ) =>
284- Cache . invalidate ( pullRequestReads , cacheKey ( input . cwd , input . number ) ) ;
262+ cli
263+ . getPullRequest ( input )
264+ . pipe (
265+ Effect . tap ( ( pullRequest ) =>
266+ Effect . sync ( ( ) => rememberLocation ( input . cwd , pullRequest , { evict : true } ) ) ,
267+ ) ,
268+ ) ;
285269
286270 const locationOf = ( input : { readonly cwd : string ; readonly number : number } ) => {
287271 const held = knownLocation ( input ) ;
@@ -318,35 +302,6 @@ export const make = Effect.gen(function* () {
318302 encodeURIComponent ( iteration . mergeBaseCommit ) ,
319303 ] . join ( "\n" ) ;
320304
321- /**
322- * The pushes a pull request has had, shared by overlapping reads the way a pull request read is.
323- * Never kept: the newest push is what the list is read for, and a push adds one.
324- */
325- const iterationReads = yield * Cache . makeWith (
326- ( key : string ) => cli . listIterations ( fromIterationKey ( key ) ) ,
327- { capacity : LOCATION_CACHE_CAPACITY , timeToLive : ( ) => Duration . zero } ,
328- ) ;
329-
330- /**
331- * One push by its id, which is all a diff cursor names. A push never changes once it lands, so
332- * the latest one is kept from every listing and a slice carrying on from it lists nothing.
333- */
334- const iterationsById = yield * Cache . makeWith (
335- ( key : string ) => {
336- const scope = fromIterationKey ( key ) ;
337- return Cache . get ( iterationReads , iterationKey ( scope ) ) . pipe (
338- Effect . map ( ( iterations ) =>
339- iterations . find ( ( candidate ) => candidate . id === scope . iterationId ) ,
340- ) ,
341- ) ;
342- } ,
343- {
344- capacity : LOCATION_CACHE_CAPACITY ,
345- timeToLive : ( exit ) =>
346- Exit . isSuccess ( exit ) && exit . value !== undefined ? Duration . infinity : Duration . zero ,
347- } ,
348- ) ;
349-
350305 /**
351306 * What one push changed, against the merge base. Never changes once the push lands, so the
352307 * detail's file count, every slice of the diff and the viewed marks share one complete read.
@@ -361,16 +316,6 @@ export const make = Effect.gen(function* () {
361316 } ,
362317 ) ;
363318
364- const listIterations = ( scope : IterationScope ) =>
365- Cache . get ( iterationReads , iterationKey ( scope ) ) . pipe (
366- Effect . tap ( ( iterations ) => {
367- const latest = iterations . at ( - 1 ) ;
368- return latest === undefined
369- ? Effect . void
370- : Cache . set ( iterationsById , iterationKey ( scope , latest . id ) , latest ) ;
371- } ) ,
372- ) ;
373-
374319 /**
375320 * Everything a diff read needs before it can ask for a file: where the repository lives, and
376321 * which pushes the pull request has had. A client names neither, and the iterations are read
@@ -380,7 +325,7 @@ export const make = Effect.gen(function* () {
380325 Effect . gen ( function * ( ) {
381326 const location = yield * locationOf ( input ) ;
382327 if ( location === null ) return null ;
383- const iterations = yield * listIterations ( {
328+ const iterations = yield * cli . listIterations ( {
384329 cwd : input . cwd ,
385330 location,
386331 number : input . number ,
@@ -534,7 +479,7 @@ export const make = Effect.gen(function* () {
534479 // riding on them, so a failure leaves it unknown rather than losing the whole detail.
535480 const countFiles = ( location : AzureDevOpsRepositoryLocation ) => {
536481 const scope = { cwd : input . cwd , location, number : input . number } ;
537- return listIterations ( scope ) . pipe (
482+ return cli . listIterations ( scope ) . pipe (
538483 Effect . flatMap ( ( iterations ) => listLatestChanges ( { ...scope , iterations } ) ) ,
539484 Effect . map ( ( listed ) => listed . changes . length ) ,
540485 Effect . orElseSucceed ( ( ) => 0 ) ,
@@ -611,12 +556,14 @@ export const make = Effect.gen(function* () {
611556 if ( location === null ) return EMPTY_DIFF_SLICE ;
612557 const scope = { cwd : input . cwd , location, number : input . number } ;
613558 const cursor = parseAzureDevOpsDiffCursor ( input . cursor ) ;
559+ // Even a fully cached continuation must check the current sign-in can read this review.
560+ const iterations = yield * cli . listIterations ( scope ) ;
614561 // Reading on stays with the push the first slice was taken against. A push landing
615562 // mid-read would otherwise renumber the files and hand the reader one twice, or none.
616563 const iteration =
617564 cursor === null
618- ? ( yield * listIterations ( scope ) ) . at ( - 1 )
619- : yield * Cache . get ( iterationsById , iterationKey ( scope , cursor . iterationId ) ) ;
565+ ? iterations . at ( - 1 )
566+ : iterations . find ( ( candidate ) => candidate . id === cursor . iterationId ) ;
620567 if ( iteration === undefined ) return EMPTY_DIFF_SLICE ;
621568 const listed = yield * Cache . get ( iterationChanges , changesKey ( scope , iteration ) ) ;
622569 const changes = listed . changes ;
@@ -772,7 +719,7 @@ export const make = Effect.gen(function* () {
772719 action : input . action ,
773720 ...( input . mergeMethod === undefined ? { } : { mergeMethod : input . mergeMethod } ) ,
774721 } )
775- . pipe ( Effect . ensuring ( forgetRead ( input ) ) , Effect . mapError ( fail ( "runAction" ) ) ) ,
722+ . pipe ( Effect . mapError ( fail ( "runAction" ) ) ) ,
776723
777724 updateChangeRequest : ( input ) =>
778725 cli
@@ -782,7 +729,7 @@ export const make = Effect.gen(function* () {
782729 title : input . title ,
783730 body : input . body ,
784731 } )
785- . pipe ( Effect . ensuring ( forgetRead ( input ) ) , Effect . mapError ( fail ( "updateChangeRequest" ) ) ) ,
732+ . pipe ( Effect . mapError ( fail ( "updateChangeRequest" ) ) ) ,
786733
787734 // Never called: `capabilities.reviewers.listCandidates` is false, and the service refuses the
788735 // list without it.
@@ -806,7 +753,7 @@ export const make = Effect.gen(function* () {
806753 reviewers : input . reviewers . map ( ( reviewer ) => reviewer . id ) ,
807754 requested : input . requested ,
808755 } )
809- . pipe ( Effect . ensuring ( forgetRead ( input ) ) , Effect . mapError ( fail ( "setReviewerRequest" ) ) ) ,
756+ . pipe ( Effect . mapError ( fail ( "setReviewerRequest" ) ) ) ,
810757
811758 // Never called: `capabilities.comment` is false, and the service refuses a comment without it.
812759 comment : ( ) => unsupported ( "comment" ) ,
0 commit comments