Skip to content
Browse files

Merge pull request #1856 from NuGet/jeffhand/commandtimeout

Set the command timeout to 5 seconds when recording package statistics
  • Loading branch information...
2 parents 77acab0 + 0428afe commit c2ff7107254771eb9b91429ba09bdd89d55844c6 @anurse anurse committed Jan 30, 2014
View
6 src/NuGetGallery.Core/Entities/EntitiesContext.cs
@@ -59,6 +59,11 @@ public override int SaveChanges()
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)
{
@@ -207,5 +212,6 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
.HasRequired(cp => cp.PackageRegistration);
}
#pragma warning restore 618
+
}
}
View
1 src/NuGetGallery.Core/Entities/IEntitiesContext.cs
@@ -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);
}
}
View
8 src/NuGetGallery/Controllers/ApiController.cs
@@ -110,16 +110,18 @@ public partial class ApiController : AppController
{
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)
{
View
6 tests/NuGetGallery.Facts/TestUtils/FakeEntitiesContext.cs
@@ -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.
Something went wrong with that request. Please try again.