Browse Source

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).
pull/35/head
Daniel Grunwald 13 years ago
parent
commit
b0fb6a4a73
  1. 18
      src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs

18
src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs

@ -22,6 +22,7 @@ namespace ICSharpCode.GitAddIn @@ -22,6 +22,7 @@ namespace ICSharpCode.GitAddIn
public static class GitStatusCache
{
static object getStatusLock = new object();
static List<KeyValuePair<string, GitStatusSet>> statusSetDict = new List<KeyValuePair<string, GitStatusSet>>();
public static void ClearCachedStatus(string fileName)
@ -46,17 +47,24 @@ namespace ICSharpCode.GitAddIn @@ -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<string, GitStatusSet>(wcRoot, statusSet));
lock (statusSetDict) {
statusSetDict.Add(new KeyValuePair<string, GitStatusSet>(wcRoot, statusSet));
}
return statusSet;
}
}

Loading…
Cancel
Save