diff --git a/src/TfsAdvanced.DataStore/Repository/BuildRepository.cs b/src/TfsAdvanced.DataStore/Repository/BuildRepository.cs index e866097..fe72f4b 100644 --- a/src/TfsAdvanced.DataStore/Repository/BuildRepository.cs +++ b/src/TfsAdvanced.DataStore/Repository/BuildRepository.cs @@ -38,7 +38,7 @@ public override bool Update(IEnumerable updates) { var updated = base.Update(updates); DateTime yesterday = DateTime.Now.Date.AddDays(-2); - base.Cleanup(x => x.QueuedDate < yesterday); + base.CleanupIfNeeded(x => x.QueuedDate < yesterday); return updated; } } diff --git a/src/TfsAdvanced.DataStore/Repository/JobRequestRepository.cs b/src/TfsAdvanced.DataStore/Repository/JobRequestRepository.cs index 1015001..8dbe2a2 100644 --- a/src/TfsAdvanced.DataStore/Repository/JobRequestRepository.cs +++ b/src/TfsAdvanced.DataStore/Repository/JobRequestRepository.cs @@ -23,7 +23,7 @@ public override bool Update(IEnumerable updates) { var updated = base.Update(updates); DateTime yesterday = DateTime.Now.Date.AddDays(-2); - base.Cleanup(x => x.QueuedTime < yesterday); + base.CleanupIfNeeded(x => x.QueuedTime < yesterday); return updated; } diff --git a/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs b/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs index 573730a..4b77ee6 100644 --- a/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs +++ b/src/TfsAdvanced.DataStore/Repository/PullRequestRepository.cs @@ -27,7 +27,7 @@ public override bool Update(IEnumerable updates) var noUpdate = base.GetList(request => !updates.Select(x => x.Id).Contains(request.Id)); bool removed = base.Remove(noUpdate); DateTime yesterday = DateTime.Now.Date.AddDays(-2); - base.Cleanup(request => request.ClosedDate.HasValue && request.ClosedDate < yesterday ); + base.CleanupIfNeeded(request => request.ClosedDate.HasValue && request.ClosedDate < yesterday ); return updated || removed; } diff --git a/src/TfsAdvanced.DataStore/Repository/RepositoryBase.cs b/src/TfsAdvanced.DataStore/Repository/RepositoryBase.cs index 77ac62d..6efa487 100644 --- a/src/TfsAdvanced.DataStore/Repository/RepositoryBase.cs +++ b/src/TfsAdvanced.DataStore/Repository/RepositoryBase.cs @@ -12,12 +12,15 @@ public abstract class RepositoryBase : IRepository protected readonly Dictionary data; protected readonly Mutex mutex; protected DateTime LastUpdated; + protected DateTime LastCleanup; + protected RepositoryBase() { this.data = new Dictionary(); this.mutex = new Mutex(); this.LastUpdated = DateTime.Now; + this.LastCleanup = DateTime.Now; } protected abstract int GetId(T item); @@ -162,7 +165,16 @@ public DateTime GetLastUpdated() return DateTime.MinValue; } - protected void Cleanup(Predicate removePredicate) + protected void CleanupIfNeeded(Predicate removePredicate) + { + // Only run cleanup every 3 hours + if (LastUpdated.AddHours(3) > DateTime.Now) + { + Cleanup(removePredicate); + } + } + + private void Cleanup(Predicate removePredicate) { if (mutex.WaitOne(60)) { @@ -174,6 +186,7 @@ protected void Cleanup(Predicate removePredicate) var key = GetId(item); data.Remove(key); } + LastCleanup = DateTime.Now; } finally { diff --git a/src/TfsAdvanced.Models/Infrastructure/AppSettings.cs b/src/TfsAdvanced.Models/Infrastructure/AppSettings.cs index 7ba2ccb..e91f027 100644 --- a/src/TfsAdvanced.Models/Infrastructure/AppSettings.cs +++ b/src/TfsAdvanced.Models/Infrastructure/AppSettings.cs @@ -14,6 +14,6 @@ public class AppSettings public AuthorizationSettings authorization { get; set; } - public static int MAX_DEGREE_OF_PARALLELISM = -1; + public static int MAX_DEGREE_OF_PARALLELISM = 3; } } \ No newline at end of file diff --git a/src/TfsAdvanced/wwwroot/js/pullRequests.js b/src/TfsAdvanced/wwwroot/js/pullRequests.js index 9395f9f..4582994 100644 --- a/src/TfsAdvanced/wwwroot/js/pullRequests.js +++ b/src/TfsAdvanced/wwwroot/js/pullRequests.js @@ -21,7 +21,9 @@ function fetchData() { function HandlMyPullRequests(myPullRequests) { - if (!myPullRequests || myPullRequests.length === 0) { + if (!myPullRequests) + return; + else if (myPullRequests.length === 0) { $("#myPullRequests").hide(); } else { $("#myPullRequests").show(); @@ -33,7 +35,9 @@ function HandlMyPullRequests(myPullRequests) { function HandleTeamPullRequests(pullRequests) { - if (!pullRequests || pullRequests.length === 0) { + if(!pullRequests) + return; + if (pullRequests.length === 0) { $("#pullRequestHeader").hide(); $("#pullRequests").hide(); $("#NoPullRequests").show(); @@ -63,7 +67,13 @@ function sortByDate(pullRequests, reverse = false) { } function HandleMyCompletedPullRequests(pullRequests) { - - sortByDate(pullRequests, true); - $("#myCompletedPullRequestsTable").html($("#completedPullRequestTemplate").tmpl(pullRequests)); + if(!pullRequests) + return; + else if (pullRequests.length === 0) { + $("#myCompletedPullRequestsTable").hide(); + } else { + $("#myCompletedPullRequestsTable").show(); + sortByDate(pullRequests, true); + $("#myCompletedPullRequestsTable").html($("#completedPullRequestTemplate").tmpl(pullRequests)); + } } \ No newline at end of file