Permalink
Browse files

Tweaking UpdateStatisticsJob to update PackageRegistrations condition…

…ally
  • Loading branch information...
1 parent cfb2db1 commit e65e33144093c3267a9315860643e229815c9894 @pranavkm pranavkm committed Aug 23, 2012
Showing with 14 additions and 11 deletions.
  1. +14 −11 Website/Infrastructure/Jobs/UpdateStatisticsJob.cs
@@ -66,20 +66,23 @@ UPDATE p
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
+ GROUP BY PackageRegistrationKey
+ ) as totals
+ ON pr.[Key] = totals.PackageRegistrationKey
+ END
+
UPDATE GallerySettings
SET DownloadStatsLastAggregatedId = @mostRecentStatisticsId
-COMMIT TRANSACTION
-
-UPDATE pr
-SET pr.DownLoadCount = totals.DownloadCount
-FROM PackageRegistrations pr INNER JOIN
-(
- SELECT PackageRegistrationKey, DownloadCount = SUM(DownloadCount)
- FROM Packages
- GROUP BY PackageRegistrationKey
-) as totals
-ON pr.[Key] = totals.PackageRegistrationKey";
+COMMIT TRANSACTION";
using (var context = _contextThunk())
{
context.Database.ExecuteSqlCommand(sql);

0 comments on commit e65e331

Please sign in to comment.