@@ -33,6 +33,7 @@ import { SESSION_RECENT_LIMIT } from "./global-sync/types"
3333import { formatServerError } from "@/utils/server-errors"
3434import { queryOptions , skipToken , useMutation , useQueries , useQuery , useQueryClient } from "@tanstack/solid-query"
3535import { createRefreshQueue } from "./global-sync/queue"
36+ import { directoryKey } from "./global-sync/utils"
3637
3738type GlobalStore = {
3839 ready : boolean
@@ -169,18 +170,20 @@ function createGlobalSync() {
169170
170171 const queue = createRefreshQueue ( {
171172 paused,
173+ key : directoryKey ,
172174 bootstrap : ( ) => queryClient . fetchQuery ( { queryKey : [ "bootstrap" ] } ) ,
173175 bootstrapInstance,
174176 } )
175177
176178 const sdkFor = ( directory : string ) => {
177- const cached = sdkCache . get ( directory )
179+ const key = directoryKey ( directory )
180+ const cached = sdkCache . get ( key )
178181 if ( cached ) return cached
179182 const sdk = globalSDK . createClient ( {
180183 directory,
181184 throwOnError : true ,
182185 } )
183- sdkCache . set ( directory , sdk )
186+ sdkCache . set ( key , sdk )
184187 return sdk
185188 }
186189
@@ -192,23 +195,25 @@ function createGlobalSync() {
192195 void bootstrapInstance ( directory )
193196 } ,
194197 onDispose : ( directory ) => {
195- queue . clear ( directory )
196- sessionMeta . delete ( directory )
197- sdkCache . delete ( directory )
198- clearProviderRev ( directory )
199- clearSessionPrefetchDirectory ( directory )
198+ const key = directoryKey ( directory )
199+ queue . clear ( key )
200+ sessionMeta . delete ( key )
201+ sdkCache . delete ( key )
202+ clearProviderRev ( key )
203+ clearSessionPrefetchDirectory ( key )
200204 } ,
201205 translate : language . t ,
202206 getSdk : sdkFor ,
203207 } )
204208
205209 async function loadSessions ( directory : string ) {
206- const pending = sessionLoads . get ( directory )
210+ const key = directoryKey ( directory )
211+ const pending = sessionLoads . get ( key )
207212 if ( pending ) return pending
208213
209- children . pin ( directory )
214+ children . pin ( key )
210215 const [ store , setStore ] = children . child ( directory , { bootstrap : false } )
211- const meta = sessionMeta . get ( directory )
216+ const meta = sessionMeta . get ( key )
212217 if ( meta && meta . limit >= store . limit ) {
213218 const next = trimSessions ( store . session , {
214219 limit : store . limit ,
@@ -218,14 +223,14 @@ function createGlobalSync() {
218223 setStore ( "session" , reconcile ( next , { key : "id" } ) )
219224 cleanupDroppedSessionCaches ( store , setStore , next , setSessionTodo )
220225 }
221- children . unpin ( directory )
226+ children . unpin ( key )
222227 return
223228 }
224229
225230 const limit = Math . max ( store . limit + SESSION_RECENT_LIMIT , SESSION_RECENT_LIMIT )
226231 const promise = queryClient
227232 . fetchQuery ( {
228- ...loadSessionsQuery ( directory ) ,
233+ ...loadSessionsQuery ( key ) ,
229234 queryFn : ( ) =>
230235 loadRootSessionsWithFallback ( {
231236 directory,
@@ -255,7 +260,7 @@ function createGlobalSync() {
255260 setStore ( "session" , reconcile ( sessions , { key : "id" } ) )
256261 cleanupDroppedSessionCaches ( store , setStore , sessions , setSessionTodo )
257262 } )
258- sessionMeta . set ( directory , { limit } )
263+ sessionMeta . set ( key , { limit } )
259264 } )
260265 . catch ( ( err ) => {
261266 console . error ( "Failed to load sessions" , err )
@@ -270,23 +275,24 @@ function createGlobalSync() {
270275 } )
271276 . then ( ( ) => { } )
272277
273- sessionLoads . set ( directory , promise )
278+ sessionLoads . set ( key , promise )
274279 void promise . finally ( ( ) => {
275- sessionLoads . delete ( directory )
276- children . unpin ( directory )
280+ sessionLoads . delete ( key )
281+ children . unpin ( key )
277282 } )
278283 return promise
279284 }
280285
281286 async function bootstrapInstance ( directory : string ) {
282- if ( ! directory ) return
283- const pending = booting . get ( directory )
287+ const key = directoryKey ( directory )
288+ if ( ! key ) return
289+ const pending = booting . get ( key )
284290 if ( pending ) return pending
285291
286- children . pin ( directory )
292+ children . pin ( key )
287293 const promise = Promise . resolve ( ) . then ( async ( ) => {
288294 const child = children . ensureChild ( directory )
289- const cache = children . vcsCache . get ( directory )
295+ const cache = children . vcsCache . get ( key )
290296 if ( ! cache ) return
291297 const sdk = sdkFor ( directory )
292298 await bootstrapDirectory ( {
@@ -307,16 +313,17 @@ function createGlobalSync() {
307313 } )
308314 } )
309315
310- booting . set ( directory , promise )
316+ booting . set ( key , promise )
311317 void promise . finally ( ( ) => {
312- booting . delete ( directory )
313- children . unpin ( directory )
318+ booting . delete ( key )
319+ children . unpin ( key )
314320 } )
315321 return promise
316322 }
317323
318324 const unsub = globalSDK . event . listen ( ( e ) => {
319325 const directory = e . name
326+ const key = directoryKey ( directory )
320327 const event = e . details
321328 const recent = bootingRoot || Date . now ( ) - bootedAt < 1500
322329
@@ -339,9 +346,9 @@ function createGlobalSync() {
339346 return
340347 }
341348
342- const existing = children . children [ directory ]
349+ const existing = children . children [ key ]
343350 if ( ! existing ) return
344- children . mark ( directory )
351+ children . mark ( key )
345352 const [ store , setStore ] = existing
346353 applyDirectoryEvent ( {
347354 event,
@@ -350,9 +357,9 @@ function createGlobalSync() {
350357 setStore,
351358 push : queue . push ,
352359 setSessionTodo,
353- vcsCache : children . vcsCache . get ( directory ) ,
360+ vcsCache : children . vcsCache . get ( key ) ,
354361 loadLsp : ( ) => {
355- void queryClient . fetchQuery ( loadLspQuery ( directory , sdkFor ( directory ) ) )
362+ void queryClient . fetchQuery ( loadLspQuery ( key , sdkFor ( directory ) ) )
356363 } ,
357364 } )
358365 } )
@@ -363,7 +370,7 @@ function createGlobalSync() {
363370 } )
364371 onCleanup ( ( ) => {
365372 for ( const directory of Object . keys ( children . children ) ) {
366- children . disposeDirectory ( directory )
373+ children . disposeDirectory ( directoryKey ( directory ) )
367374 }
368375 } )
369376
0 commit comments