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).
newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
ec95374d67
  1. 10
      src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs

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

@ -23,6 +23,7 @@ namespace ICSharpCode.GitAddIn @@ -23,6 +23,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)
@ -47,17 +48,24 @@ namespace ICSharpCode.GitAddIn @@ -47,17 +48,24 @@ namespace ICSharpCode.GitAddIn
public static GitStatusSet GetStatusSet(string wcRoot)
{
lock (statusSetDict) {
// Prevent multiple GetStatusSet calls from running in parallel
lock (getStatusLock) {
GitStatusSet statusSet;
// 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);
lock (statusSetDict) {
statusSetDict.Add(new KeyValuePair<string, GitStatusSet>(wcRoot, statusSet));
}
return statusSet;
}
}

Loading…
Cancel
Save