Skip to content

Commit

Permalink
Merge pull request #52 from BertCotton/FixingPullRequestJs
Browse files Browse the repository at this point in the history
Adding cleanup only if needed.
  • Loading branch information
BertCotton authored Aug 30, 2017
2 parents fb99375 + d22b875 commit 1a452a0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/TfsAdvanced.DataStore/Repository/BuildRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override bool Update(IEnumerable<Build> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override bool Update(IEnumerable<QueueJob> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override bool Update(IEnumerable<PullRequest> 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;

}
Expand Down
15 changes: 14 additions & 1 deletion src/TfsAdvanced.DataStore/Repository/RepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ public abstract class RepositoryBase<T> : IRepository<T>
protected readonly Dictionary<int, T> data;
protected readonly Mutex mutex;
protected DateTime LastUpdated;
protected DateTime LastCleanup;


protected RepositoryBase()
{
this.data = new Dictionary<int, T>();
this.mutex = new Mutex();
this.LastUpdated = DateTime.Now;
this.LastCleanup = DateTime.Now;
}

protected abstract int GetId(T item);
Expand Down Expand Up @@ -162,7 +165,16 @@ public DateTime GetLastUpdated()
return DateTime.MinValue;
}

protected void Cleanup(Predicate<T> removePredicate)
protected void CleanupIfNeeded(Predicate<T> removePredicate)
{
// Only run cleanup every 3 hours
if (LastUpdated.AddHours(3) > DateTime.Now)
{
Cleanup(removePredicate);
}
}

private void Cleanup(Predicate<T> removePredicate)
{
if (mutex.WaitOne(60))
{
Expand All @@ -174,6 +186,7 @@ protected void Cleanup(Predicate<T> removePredicate)
var key = GetId(item);
data.Remove(key);
}
LastCleanup = DateTime.Now;
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion src/TfsAdvanced.Models/Infrastructure/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
20 changes: 15 additions & 5 deletions src/TfsAdvanced/wwwroot/js/pullRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 1a452a0

Please sign in to comment.