Ejegg has submitted this change and it was merged.

Change subject: Keep donatewiki counts up to date
......................................................................


Keep donatewiki counts up to date

Bug: T114010
Change-Id: If513acdb8ea628bd16a3ff7457c20c8d550ef347
---
M fundraiser/analytics/management/commands/LoadLPImpressions.py
1 file changed, 18 insertions(+), 0 deletions(-)

Approvals:
  Ejegg: Verified
  Awight: Looks good to me, approved



diff --git a/fundraiser/analytics/management/commands/LoadLPImpressions.py 
b/fundraiser/analytics/management/commands/LoadLPImpressions.py
index 1a18da2..ef88959 100644
--- a/fundraiser/analytics/management/commands/LoadLPImpressions.py
+++ b/fundraiser/analytics/management/commands/LoadLPImpressions.py
@@ -399,6 +399,7 @@
                             try:
                                 if not self.debug:
                                     self.write(self.unique_sql, 
self.pending_uniques)
+                                    self.update_donatewiki_counts()
                             except Exception:
                                 self.logger.exception("Error writing 
donatewiki uniques to the database")
                             finally:
@@ -414,6 +415,7 @@
                 if not self.debug:
                     self.write(self.impression_sql, self.pending_impressions)
                     self.write(self.unique_sql, self.pending_uniques)
+                    self.update_donatewiki_counts()
                 self.pending_impressions = []
                 self.pending_uniques = []
 
@@ -475,3 +477,19 @@
 
             for i in impressions:
                 self.write(base_sql, [i])
+
+    @transaction.commit_manually
+    def update_donatewiki_counts(self):
+        """
+        Keep the donatewiki_counts table up to date
+        """
+        cursor = connections['default'].cursor()
+
+        try:
+            cursor.execute('TRUNCATE donatewiki_counts')
+            cursor.execute('INSERT INTO donatewiki_counts (utm_source, 
utm_campaign, link_id, count) SELECT utm_source, utm_campaign, link_id, 
COUNT(*) FROM donatewiki_unique GROUP BY utm_source, utm_campaign, link_id 
ORDER BY utm_campaign, utm_source, link_id')
+            transaction.commit('default')
+
+        except Exception as e:
+            transaction.rollback()
+            self.logger.exception("UNHANDLED EXCEPTION UPDATING DONATEWIKI 
COUNTS")

-- 
To view, visit https://gerrit.wikimedia.org/r/259424
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If513acdb8ea628bd16a3ff7457c20c8d550ef347
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/tools/DjangoBannerStats
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to