Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { GitCapabilityCache } from '../../shared/git-capability-cache'
|
||||
import { measureUtf8ByteLength } from '../../shared/utf8-byte-limits'
|
||||
import { parseWslUncPath } from '../../shared/wsl-paths'
|
||||
|
||||
type LocalGitCapabilityTarget = {
|
||||
@@ -7,8 +6,6 @@ type LocalGitCapabilityTarget = {
|
||||
wslDistro?: string
|
||||
}
|
||||
|
||||
export const LOCAL_GIT_CAPABILITY_HOST_MAX_ENTRIES = 64
|
||||
export const LOCAL_GIT_CAPABILITY_HOST_KEY_MAX_BYTES = 4 * 1024
|
||||
const localCapabilitiesByExecutionHost = new Map<string, GitCapabilityCache>()
|
||||
// Why: reconnecting creates a new provider, while concurrent IPC/runtime users
|
||||
// of one SSH connection must share the same remote Git capability results.
|
||||
@@ -24,24 +21,10 @@ export function getLocalGitCapabilityCache(
|
||||
target: LocalGitCapabilityTarget = {}
|
||||
): GitCapabilityCache {
|
||||
const executionHost = getLocalGitExecutionHostKey(target)
|
||||
if (
|
||||
measureUtf8ByteLength(executionHost, {
|
||||
stopAfterBytes: LOCAL_GIT_CAPABILITY_HOST_KEY_MAX_BYTES
|
||||
}).exceededLimit
|
||||
) {
|
||||
return new GitCapabilityCache()
|
||||
}
|
||||
let cache = localCapabilitiesByExecutionHost.get(executionHost)
|
||||
if (!cache) {
|
||||
cache = new GitCapabilityCache()
|
||||
localCapabilitiesByExecutionHost.set(executionHost, cache)
|
||||
while (localCapabilitiesByExecutionHost.size > LOCAL_GIT_CAPABILITY_HOST_MAX_ENTRIES) {
|
||||
const oldestHost = localCapabilitiesByExecutionHost.keys().next().value
|
||||
if (oldestHost === undefined) {
|
||||
break
|
||||
}
|
||||
localCapabilitiesByExecutionHost.delete(oldestHost)
|
||||
}
|
||||
}
|
||||
return cache
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user