@@ -342,24 +342,28 @@ def _detect_ssh_host_from_vscode(vscode_server_dir: str) -> Optional[str]:
342342 history = os .path .join (vscode_server_dir , "data" , "User" , "History" )
343343 if not os .path .isdir (history ):
344344 return None
345- best : dict = {} # host -> 最新 mtime
345+ # entries.json 候補を mtime 降順で集め、**新しい方から 1 ファイルずつ読み、最初に
346+ # ssh-remote ホストが見つかった時点で即 return** する (History が数千ファイルに
347+ # 膨れても全読み込みを避け、devbase up の遅延を防ぐ)。mtime 収集は stat のみで安価。
348+ candidates = []
346349 for root , _dirs , files in os .walk (history ):
347- for name in files :
348- if name != "entries.json" : # resource authority は entries.json に載る
349- continue
350- path = os .path .join (root , name )
351- try :
352- mtime = os .path .getmtime (path )
353- with open (path , encoding = "utf-8" , errors = "ignore" ) as f :
354- text = f .read ()
355- except OSError :
356- continue
357- for host in _SSH_REMOTE_RE .findall (text ):
358- if host and (host not in best or mtime > best [host ]):
359- best [host ] = mtime
360- if not best :
361- return None
362- return max (best , key = best .get )
350+ if "entries.json" not in files : # resource authority は entries.json に載る
351+ continue
352+ path = os .path .join (root , "entries.json" )
353+ try :
354+ candidates .append ((os .path .getmtime (path ), path ))
355+ except OSError :
356+ continue
357+ for _mtime , path in sorted (candidates , key = lambda t : t [0 ], reverse = True ):
358+ try :
359+ with open (path , encoding = "utf-8" , errors = "ignore" ) as f :
360+ text = f .read ()
361+ except OSError :
362+ continue
363+ match = _SSH_REMOTE_RE .search (text )
364+ if match :
365+ return match .group (1 )
366+ return None
363367
364368
365369def resolve_editor_ssh_host (environ = None ,
0 commit comments