Browse files

Fixing the stats aggregation bug, and using a stored procedure in the…

… process.
  • Loading branch information...
1 parent 98268b8 commit 08211b2440e94ca6b4b2d17be673bb308c403659 @jeffhandley jeffhandley committed Aug 30, 2012
View
63 Website/Infrastructure/AggregateStatistics.sql
@@ -0,0 +1,63 @@
+SET ANSI_NULLS ON
+SET QUOTED_IDENTIFIER ON
+IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AggregateStatistics]') AND type in (N'P', N'PC'))
+BEGIN
+EXEC dbo.sp_executesql @statement = N'
+CREATE PROCEDURE [dbo].[AggregateStatistics]
+AS
+ SET NOCOUNT ON
+
+ DECLARE @mostRecentStatisticsId int
+ DECLARE @lastAggregatedStatisticsId int
+
+ SELECT @mostRecentStatisticsId = MAX([Key]) FROM PackageStatistics
+ SELECT @lastAggregatedStatisticsId = DownloadStatsLastAggregatedId FROM GallerySettings
+ SELECT @lastAggregatedStatisticsId = ISNULL(@lastAggregatedStatisticsId, 0)
+
+ IF (@mostRecentStatisticsId IS NULL)
+ RETURN
+
+ DECLARE @DownloadStats TABLE
+ (
+ PackageKey int PRIMARY KEY
+ , DownloadCount int
+ )
+
+ DECLARE @AffectedPackages TABLE
+ (
+ PackageRegistrationKey int
+ )
+
+ INSERT @DownloadStats
+ SELECT stats.PackageKey, DownloadCount = COUNT(1)
+ FROM PackageStatistics stats
+ WHERE [Key] > @lastAggregatedStatisticsId
+ AND [Key] <= @mostRecentStatisticsId
+ GROUP BY stats.PackageKey
+
+ BEGIN TRANSACTION
+
+ UPDATE Packages
+ SET Packages.DownloadCount = Packages.DownloadCount + stats.DownloadCount
@pranavkm
NuGet member
pranavkm added a note Sep 7, 2012

Do you think you could also set the LastUpdated date? It would allow us to update the index

@jeffhandley
NuGet member

Won't that make it look like the package itself has been updated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ OUTPUT inserted.PackageRegistrationKey INTO @AffectedPackages
+ FROM Packages
+ INNER JOIN @DownloadStats stats ON Packages.[Key] = stats.PackageKey
+
+ UPDATE PackageRegistrations
+ SET DownloadCount = TotalDownloadCount
+ FROM (
+ SELECT Packages.PackageRegistrationKey
+ , SUM(Packages.DownloadCount) AS TotalDownloadCount
+ FROM (SELECT DISTINCT PackageRegistrationKey FROM @AffectedPackages) affected
+ INNER JOIN Packages ON Packages.PackageRegistrationKey = affected.PackageRegistrationKey
+ GROUP BY Packages.PackageRegistrationKey
+ ) AffectedPackageRegistrations
+ INNER JOIN PackageRegistrations ON PackageRegistrations.[Key] = AffectedPackageRegistrations.PackageRegistrationKey
+
+ UPDATE GallerySettings
+ SET DownloadStatsLastAggregatedId = @mostRecentStatisticsId
+
+ COMMIT TRANSACTION
+'
+END
+GO
View
49 Website/Infrastructure/Jobs/UpdateStatisticsJob.cs
@@ -26,55 +26,8 @@ public override Task Execute()
private void UpdateStats()
{
- const string sql = @"
-DECLARE @mostRecentStatisticsId int
-DECLARE @lastAggregatedStatisticsId int
+ const string sql = "EXEC [dbo].[AggregateStatistics]";
-SELECT @mostRecentStatisticsId = MAX([Key]) FROM PackageStatistics
-SELECT @lastAggregatedStatisticsId = DownloadStatsLastAggregatedId FROM GallerySettings
-SELECT @lastAggregatedStatisticsId = ISNULL(@lastAggregatedStatisticsId, 0)
-
-IF (@mostRecentStatisticsId IS NULL)
-RETURN
-
-DECLARE @DownloadStats TABLE
-(
- PackageKey int PRIMARY KEY,
- DownloadCount int
-)
-
-INSERT INTO @DownloadStats
-SELECT stats.PackageKey, DownloadCount = COUNT(1)
-FROM PackageStatistics stats
-WHERE [Key] > @lastAggregatedStatisticsId AND
- [Key] <= @mostRecentStatisticsId
-GROUP BY stats.PackageKey
-
-BEGIN TRANSACTION
-
- UPDATE p
- SET p.DownloadCount = p.DownloadCount + stats.DownloadCount
- FROM Packages p INNER JOIN @DownloadStats stats
- ON p.[Key] = stats.PackageKey
-
- IF @@ROWCOUNT > 0
- BEGIN
- UPDATE pr
- SET pr.DownloadCount = totals.DownloadCount
- FROM PackageRegistrations pr INNER JOIN
- (
- SELECT PackageRegistrationKey, DownloadCount = SUM(DownloadCount)
- FROM Packages
- WHERE EXISTS(SELECT * FROM @DownloadStats stats WHERE stats.PackageKey = Packages.PackageRegistrationKey)
- GROUP BY PackageRegistrationKey
- ) as totals
- ON pr.[Key] = totals.PackageRegistrationKey
- END
-
- UPDATE GallerySettings
- SET DownloadStatsLastAggregatedId = @mostRecentStatisticsId
-
-COMMIT TRANSACTION";
using (var context = _contextThunk())
{
context.Database.ExecuteSqlCommand(sql);
View
24 Website/Migrations/201208302051344_CreateAggregateStatisticsSP.Designer.cs
@@ -0,0 +1,24 @@
+// <auto-generated />
+namespace NuGetGallery.Migrations
+{
+ using System.Data.Entity.Migrations;
+ using System.Data.Entity.Migrations.Infrastructure;
+
+ public sealed partial class CreateAggregateStatisticsSP : IMigrationMetadata
+ {
+ string IMigrationMetadata.Id
+ {
+ get { return "201208302051344_CreateAggregateStatisticsSP"; }
+ }
+
+ string IMigrationMetadata.Source
+ {
+ get { return null; }
+ }
+
+ string IMigrationMetadata.Target
+ {
+ get { return "H4sIAAAAAAAEAO0923LjupHvW5V/UOlps1WxPLPJ1MkpOykfz8yJk7nVaCb76KIlWMM9FKmQ1IydX8tDPml/YQlecekGGiRISXP84rIAsNFoNBqNRjf6//7174s/P2yj2VeWZmESX86fnZ3PZyxeJesw3lzO9/n9736Y//lPv/mPi1fr7cPs702757xd8WWcXc6/5Pnux8UiW31h2yA724arNMmS+/xslWwXwTpZPD8//2Hx7HzBChDzAtZsdvFxH+fhlpU/ip/XSbxiu3wfRG+TNYuyuryoWZZQZ++CLct2wYpdzt/tf2b5z0EUsfRxPruKwqDAYcmie0eEzv/IEZq3XRWdvSqQyh8/Pe5Y2eHl/HqfBjlbv2ZsLTYsmv6NPUoFRdGHNNmxNH/8yO7rz4tG89lC/nChftl+J37Ecbic38T5fz+fz97toyi4i4qC+yDK2Hy2e/HjMk9S9jOLWYnghyDPWVrMy82alWOoafHj7gWNHH9cnD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jH0KTajdd7cPmIdN/WGTpGck1iP4v0U1qvYxtCzKR0l1r1w94H1LjQxdC5k5LJ13cZU6l12VVBXXfYoWxdK9JzekdoA6k7N8kMkqWyOxagqtzIQVs76QRHdiODrqjAR7iQAuwOVaTfC9wyhUfdyv7sYRFBAWxLFYfOcvIKQ/Cy10fd+JrQFdjjESR9QLFsiNAWazoK5VgtfyhWqgikPizBk2ckcGKrBC/1EhkjwhwbG7epFbT/vCiME6w2kglUVMSVGW+WLXLLHLk4gg2cvbr7U8a/Kj4QERq9SgBR0L9RRuQSijXeiQI6POEmsbpJ9BwB9pyucSNpqf8RodUScAni6ZU/DllVdIMOyx7mXFFPDrJuTDnsauK5xI3mGvREASEmCEsHiJOWTEJruDydH8UYG2LsHJwXBG2igLmHQ2NEkd+OQQ3VHIVLF6MVyksTR/Scw7dKUc23QwNUzlJwRzusQa8uyeYhwiiHNN0BAFkJ00iGabqotSqEl3Zp/3VA9yIIp40YiCT7/DundBjH7tESw3wUS9WRjIrbxlWXMAmFMOTcq+XBOcrzY8rNrjEwgLf1XW3exqCw8dUHxU0vzdbH4uI/5yyvVr5csCzcdCJ68LGYr6RanbcNf/WpukxSMmibKmw9vWR6sgzy4SvPwPljlRfWKZVlpdPx7EO1Li8YdW9/E7/f5bp8XQ2bbu0jSPvmllKn/i4WG88X78pWyzMcQCjRD/ljN+/infRitW7xfAw9WICD4bVf9EhGfSz7pbPPYQnqXxERANfnaS7pPbLuL+Ive7+Nl8JXhuNlpKFPs4mUYbAodWKRgVdI8wRXwJ+W6LooOxC+6/oqfBbuutw9/+n/7fCqPtBgBAA=="; }
+ }
+ }
+}
View
13 Website/Migrations/201208302051344_CreateAggregateStatisticsSP.cs
@@ -0,0 +1,13 @@
+namespace NuGetGallery.Migrations
+{
+ using System.Data.Entity.Migrations;
+ using System.IO;
+
+ public partial class CreateAggregateStatisticsSP : SqlResourceMigration
+ {
+ public CreateAggregateStatisticsSP()
+ : base("NuGetGallery.Infrastructure.AggregateStatistics.sql")
+ {
+ }
+ }
+}
View
42 Website/Migrations/SqlResourceMigration.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Data.Entity.Migrations;
+using System.IO;
+
+namespace NuGetGallery.Migrations
+{
+ public class SqlResourceMigration : DbMigration
+ {
+ private string _sqlFile;
+ private static readonly string[] Go = new[] { "GO" };
+
+ public SqlResourceMigration(string embeddedResourceSqlFile)
+ {
+ _sqlFile = embeddedResourceSqlFile;
+ }
+
+ public override void Up()
+ {
+ using (var stream = typeof(ExecuteELMAHSql).Assembly.GetManifestResourceStream(_sqlFile))
+ {
+ using (var streamReader = new StreamReader(stream))
+ {
+ var statements = streamReader.ReadToEnd().Split(Go, StringSplitOptions.RemoveEmptyEntries);
+
+ foreach (var statement in statements)
+ {
+ if (String.IsNullOrWhiteSpace(statement))
+ {
+ continue;
+ }
+
+ Sql(statement);
+ }
+ }
+ }
+ }
+
+ public override void Down()
+ {
+ }
+ }
+}
View
6 Website/Website.csproj
@@ -370,7 +370,12 @@
<Compile Include="Migrations\201208230640333_PackageSortingIndexes.Designer.cs">
<DependentUpon>201208230640333_PackageSortingIndexes.cs</DependentUpon>
</Compile>
+ <Compile Include="Migrations\201208302051344_CreateAggregateStatisticsSP.cs" />
+ <Compile Include="Migrations\201208302051344_CreateAggregateStatisticsSP.Designer.cs">
+ <DependentUpon>201208302051344_CreateAggregateStatisticsSP.cs</DependentUpon>
+ </Compile>
<Compile Include="Migrations\MigrationsConfiguration.cs" />
+ <Compile Include="Migrations\SqlResourceMigration.cs" />
<Compile Include="PackageCurators\IAutomaticPackageCurator.cs" />
<Compile Include="PackageCurators\AutomaticPackageCurator.cs" />
<Compile Include="PackageCurators\TagBasedPackageCurator.cs" />
@@ -814,6 +819,7 @@
<Content Include="Errors\Error.html" />
<Content Include="favicon.ico" />
<EmbeddedResource Include="Infrastructure\Elmah.SqlServer.sql" />
+ <EmbeddedResource Include="Infrastructure\AggregateStatistics.sql" />
<Content Include="Scripts\stats.js" />
<Content Include="Scripts\jquery-1.6.2-vsdoc.js" />
<Content Include="Scripts\jquery-1.6.2.js" />

0 comments on commit 08211b2

Please sign in to comment.