Skip to content

Commit

Permalink
Merge pull request #1856 from NuGet/jeffhand/commandtimeout
Browse files Browse the repository at this point in the history
Set the command timeout to 5 seconds when recording package statistics
  • Loading branch information
analogrelay committed Jan 30, 2014
2 parents 77acab0 + 0428afe commit c2ff710
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/NuGetGallery.Core/Entities/EntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public void DeleteOnCommit<T>(T entity) where T : class
Set<T>().Remove(entity);
}

public void SetCommandTimeout(int? seconds)
{
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = seconds;
}

#pragma warning disable 618 // TODO: remove Package.Authors completely once prodution services definitely no longer need it
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -207,5 +212,6 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
.HasRequired(cp => cp.PackageRegistration);
}
#pragma warning restore 618

}
}
1 change: 1 addition & 0 deletions src/NuGetGallery.Core/Entities/IEntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface IEntitiesContext
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set", Justification="This is to match the EF terminology.")]
IDbSet<T> Set<T>() where T : class;
void DeleteOnCommit<T>(T entity) where T : class;
void SetCommandTimeout(int? seconds);
}
}
8 changes: 5 additions & 3 deletions src/NuGetGallery/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,18 @@ public virtual async Task<ActionResult> GetPackage(string id, string version)
{
var stats = new PackageStatistics
{
// IMPORTANT: Timestamp is managed by the database.
IPAddress = Request.UserHostAddress,
UserAgent = Request.UserAgent,
Package = package,
Operation = Request.Headers["NuGet-Operation"],
DependentPackage = Request.Headers["NuGet-DependentPackage"],
ProjectGuids = Request.Headers["NuGet-ProjectGuids"],
};
//Temporarily disable stats.
// PackageService.AddDownloadStatistics(stats);

// Only allow this to take up to 5 seconds. Any longer and we just lose the data; oh well.
EntitiesContext.SetCommandTimeout(5);

PackageService.AddDownloadStatistics(stats);
}
catch (ReadOnlyModeException)
{
Expand Down
6 changes: 6 additions & 0 deletions tests/NuGetGallery.Facts/TestUtils/FakeEntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ public void VerifyCommitChanges()
{
Assert.True(areChangesSaved, "SaveChanges() has not been called on the entity context.");
}


public void SetCommandTimeout(int? seconds)
{
throw new NotSupportedException();
}
}
}

0 comments on commit c2ff710

Please sign in to comment.