@@ -216,33 +216,35 @@ class Dependency {
216216
217217const DependenciesToAExprs = {
218218 _depsToAExprs : new BidirectionalMultiMap ( ) ,
219+ _AEsPerFile : new Map ( ) ,
219220
220221 associate ( dep , aexpr ) {
222+ const location = aexpr . meta ( ) . get ( "location" ) . file ;
223+ if ( ! this . _AEsPerFile . has ( location ) ) {
224+ this . _AEsPerFile . set ( location , new Set ( ) ) ;
225+ }
226+ this . _AEsPerFile . get ( location ) . add ( aexpr ) ;
221227 this . _depsToAExprs . associate ( dep , aexpr ) ;
222228 dep . updateTracking ( ) ;
223229 debouncedUpdateDebuggingViews ( ) ;
224230 } ,
225231
226232 disconnectAllForAExpr ( aexpr ) {
233+ const location = aexpr . meta ( ) . get ( "location" ) . file ;
234+ if ( this . _AEsPerFile . has ( location ) ) {
235+ this . _AEsPerFile . get ( location ) . delete ( aexpr ) ;
236+ }
227237 const deps = this . getDepsForAExpr ( aexpr ) ;
228238 this . _depsToAExprs . removeAllLeftFor ( aexpr ) ;
229239 deps . forEach ( dep => dep . updateTracking ( ) ) ;
230240 debouncedUpdateDebuggingViews ( ) ;
231241 } ,
232242
233- getAETriplesForFile ( url ) {
234- const result = [ ] ;
235- for ( const ae of this . _depsToAExprs . getAllRight ( ) ) {
236- const location = ae . meta ( ) . get ( "location" ) . file ;
237- if ( location . includes ( url ) ) {
238- for ( const dependency of this . getDepsForAExpr ( ae ) ) {
239- for ( const hook of HooksToDependencies . getHooksForDep ( dependency ) ) {
240- result . push ( { hook, dependency, ae } ) ;
241- }
242- }
243- }
243+ getAEsInFile ( url ) {
244+ for ( const [ location , aes ] of this . _AEsPerFile . entries ( ) ) {
245+ if ( location . includes ( url ) ) return aes ;
244246 }
245- return result ;
247+ return [ ] ;
246248 } ,
247249
248250 getAExprsForDep ( dep ) {
@@ -275,24 +277,20 @@ const HooksToDependencies = {
275277 this . _hooksToDeps . associate ( hook , dep ) ;
276278 debouncedUpdateDebuggingViews ( ) ;
277279 } ,
280+
278281 remove ( hook , dep ) {
279282 this . _hooksToDeps . remove ( hook , dep ) ;
280283 debouncedUpdateDebuggingViews ( ) ;
281284 } ,
282285
283- async getHookTriplesForFile ( url ) {
284- const result = [ ] ;
285- for ( const hook of this . _hooksToDeps . getAllLeft ( ) ) {
286- const locations = await hook . getLocations ( ) ;
287- if ( locations . some ( loc => loc && loc . source . includes ( url ) ) ) {
288- for ( const dependency of this . getDepsForHook ( hook ) ) {
289- for ( const ae of DependenciesToAExprs . getAExprsForDep ( dependency ) ) {
290- result . push ( { hook, dependency, ae } ) ;
291- }
292- }
293- }
294- }
295- return result ;
286+ async getHooksInFile ( url ) {
287+ const hooksWithLocations = await Promise . all ( this . _hooksToDeps . getAllLeft ( ) . map ( hook => {
288+ return hook . getLocations ( ) . then ( locations => { return { hook, locations} } ) ;
289+ } ) )
290+ return hooksWithLocations . filter ( ( { hook, locations} ) => {
291+ const location = locations . find ( loc => loc && loc . source ) ;
292+ return location && locations . source . includes ( url ) ;
293+ } ) . map ( ( { hook, locations} ) => hook ) ;
296294 } ,
297295
298296 disconnectAllForDependency ( dep ) {
@@ -932,12 +930,19 @@ export async function registerFileForAEDebugging(url, context, triplesCallback)
932930
933931export async function getDependencyTriplesForFile ( url ) {
934932 const result = [ ] ;
935- for ( const hook of HooksToDependencies . _hooksToDeps . getAllLeft ( ) ) {
936- const locations = await hook . getLocations ( ) ;
933+ for ( const ae of DependenciesToAExprs . getAEsInFile ( url ) ) {
934+ for ( const dependency of DependenciesToAExprs . getDepsForAExpr ( ae ) ) {
935+ for ( const hook of HooksToDependencies . getHooksForDep ( dependency ) ) {
936+ result . push ( { hook, dependency, ae } ) ;
937+ }
938+ }
939+ }
940+ for ( const hook of await HooksToDependencies . getHooksInFile ( url ) ) {
937941 for ( const dependency of HooksToDependencies . getDepsForHook ( hook ) ) {
938- for ( const ae of DependenciesToAExprs . getAExprsForDep ( dependency ) ) {
942+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dependency ) ) {
939943 const location = ae . meta ( ) . get ( "location" ) . file ;
940- if ( location . includes ( url ) || locations . some ( loc => loc && loc . file . includes ( url ) ) ) {
944+ // if the AE is also in this file, we already covered it with the previous loop
945+ if ( ! location . includes ( url ) ) {
941946 result . push ( { hook, dependency, ae } ) ;
942947 }
943948 }
0 commit comments