From b0fb6a4a7395d35003aa3fff20df1db27ea199e7 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 20 Jan 2013 19:29:28 +0100 Subject: [PATCH] GitStatusCache: calling ClearCachedStatus() shouldn't wait for running GetStatusSet() calls in the background. This fixes a performance issue when running "Include In Project" on a folder with many files (when using git). --- .../GitAddIn/Src/GitStatusCache.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs b/src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs index c856dcc3f9..ee68007bff 100644 --- a/src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs +++ b/src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs @@ -22,6 +22,7 @@ namespace ICSharpCode.GitAddIn public static class GitStatusCache { + static object getStatusLock = new object(); static List> statusSetDict = new List>(); public static void ClearCachedStatus(string fileName) @@ -46,17 +47,24 @@ namespace ICSharpCode.GitAddIn public static GitStatusSet GetStatusSet(string wcRoot) { - lock (statusSetDict) { + // Prevent multiple GetStatusSet calls from running in parallel + lock (getStatusLock) { GitStatusSet statusSet; - foreach (var pair in statusSetDict) { - if (FileUtility.IsEqualFileName(pair.Key, wcRoot)) - return pair.Value; + // Don't hold statusSetDict during the whole operation; we don't want + // to slow down other threads calling ClearCachedStatus() + lock (statusSetDict) { + foreach (var pair in statusSetDict) { + if (FileUtility.IsEqualFileName(pair.Key, wcRoot)) + return pair.Value; + } } statusSet = new GitStatusSet(); GitGetFiles(wcRoot, statusSet); GitGetStatus(wcRoot, statusSet); - statusSetDict.Add(new KeyValuePair(wcRoot, statusSet)); + lock (statusSetDict) { + statusSetDict.Add(new KeyValuePair(wcRoot, statusSet)); + } return statusSet; } }