Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Tweaking UpdateStatisticsJob to update PackageRegistrations conditi…

…onally

* Fixing collation issue in DownloadCount column. Fies #524
  • Loading branch information...
commit 8523bb27a3591036b68c8f383c2eb89981610f7b 1 parent ab7ff35
@pranavkm pranavkm authored
Showing with 16 additions and 13 deletions.
  1. +16 −13 Website/Infrastructure/Jobs/UpdateStatisticsJob.cs
View
29 Website/Infrastructure/Jobs/UpdateStatisticsJob.cs
@@ -51,7 +51,7 @@ DownloadCount int
GROUP BY stats.PackageKey
UPDATE tmp
-SET DownLoadCount = tmp.DownloadCount + p.DownloadCount
+SET DownloadCount = tmp.DownloadCount + p.DownloadCount
FROM @DownloadStats tmp INNER JOIN
(
SELECT [Key], DownloadCount
@@ -62,24 +62,27 @@ FROM Packages
BEGIN TRANSACTION
UPDATE p
- SET p.DownLoadCount = stats.DownloadCount
+ SET 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
+ 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);
Please sign in to comment.
Something went wrong with that request. Please try again.