Skip to content
This repository
Browse code

Fixing update stats job to A) combine two steps into one, and (more i…

…mportantly) B) only update the affected packages instead of ALL packages on each recalc.
  • Loading branch information...
commit f09a380ed499233bddfd94244fd146693020097a 1 parent 77403a1
Jeff Handley authored August 28, 2012
14  Website/Infrastructure/Jobs/UpdateStatisticsJob.cs
@@ -50,22 +50,13 @@ DownloadCount int
50 50
     [Key] <= @mostRecentStatisticsId
51 51
 GROUP BY stats.PackageKey
52 52
 
53  
-UPDATE tmp
54  
-SET DownloadCount = tmp.DownloadCount + p.DownloadCount
55  
-FROM @DownloadStats tmp INNER JOIN 
56  
-(
57  
-    SELECT [Key], DownloadCount
58  
-    FROM Packages
59  
-) p
60  
-ON p.[Key] = tmp.PackageKey
61  
-
62 53
 BEGIN TRANSACTION
63 54
 
64 55
     UPDATE p
65  
-    SET p.DownloadCount = stats.DownloadCount
  56
+    SET p.DownloadCount = p.DownloadCount + stats.DownloadCount
66 57
     FROM Packages p INNER JOIN @DownloadStats stats
67 58
     ON p.[Key] = stats.PackageKey
68  
-
  59
+    
69 60
     IF @@ROWCOUNT > 0
70 61
     BEGIN
71 62
         UPDATE pr
@@ -74,6 +65,7 @@ UPDATE pr
74 65
         (
75 66
             SELECT PackageRegistrationKey, DownloadCount = SUM(DownloadCount)
76 67
             FROM Packages
  68
+            WHERE EXISTS(SELECT * FROM @DownloadStats stats WHERE stats.PackageKey = Packages.PackageRegistrationKey)
77 69
             GROUP BY PackageRegistrationKey
78 70
         ) as totals
79 71
         ON pr.[Key] = totals.PackageRegistrationKey

0 notes on commit f09a380

Pranav K

I think this join is incorrect. PackageKey is from the Packages table. This should probably be
stats.PackageKey = Packages.[Key]

Please sign in to comment.
Something went wrong with that request. Please try again.