Skip to content

Tweaking UpdateStatisticsJob to update PackageRegistrations conditionally #581

Closed
wants to merge 1 commit into from
View
25 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);
Something went wrong with that request. Please try again.