Refactored workspace name loading logic

This commit is contained in:
Thorsten Sommer 2026-03-05 17:28:28 +01:00
parent 544d339699
commit 89f6a34bc7
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -530,12 +530,9 @@ public static class WorkspaceBehaviour
await EnsureTreeShellLoadedCoreAsync(); await EnsureTreeShellLoadedCoreAsync();
if (WORKSPACE_TREE_CACHE.Workspaces.TryGetValue(workspaceId, out var cachedWorkspace) && !string.IsNullOrWhiteSpace(cachedWorkspace.WorkspaceName)) if (WORKSPACE_TREE_CACHE.Workspaces.TryGetValue(workspaceId, out var cachedWorkspace) && !string.IsNullOrWhiteSpace(cachedWorkspace.WorkspaceName))
return cachedWorkspace.WorkspaceName; return cachedWorkspace.WorkspaceName;
}
finally
{
WORKSPACE_TREE_CACHE_SEMAPHORE.Release();
}
// Not in cache — read from disk and update cache in the same semaphore scope
// to avoid a second semaphore acquisition via UpdateWorkspaceNameInCacheAsync:
var workspacePath = Path.Join(WorkspaceRootDirectory, workspaceId.ToString()); var workspacePath = Path.Join(WorkspaceRootDirectory, workspaceId.ToString());
var workspaceNamePath = Path.Join(workspacePath, "name"); var workspaceNamePath = Path.Join(workspacePath, "name");
string workspaceName; string workspaceName;
@ -563,9 +560,17 @@ public static class WorkspaceBehaviour
workspaceName = TB("Unnamed workspace"); workspaceName = TB("Unnamed workspace");
} }
await UpdateWorkspaceNameInCacheAsync(workspaceId, workspaceName); // Update the cache directly (we already hold the semaphore):
if (WORKSPACE_TREE_CACHE.Workspaces.TryGetValue(workspaceId, out var workspace))
workspace.WorkspaceName = workspaceName;
return workspaceName; return workspaceName;
} }
finally
{
WORKSPACE_TREE_CACHE_SEMAPHORE.Release();
}
}
public static async Task DeleteChatAsync(IDialogService dialogService, Guid workspaceId, Guid chatId, bool askForConfirmation = true) public static async Task DeleteChatAsync(IDialogService dialogService, Guid workspaceId, Guid chatId, bool askForConfirmation = true)
{ {