Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/stats.js

Issue 5968535989780480: Issue 2567 - Simplified stats data structure, fixed regression resetting ad counter (Closed)
Patch Set: Created May 22, 2015, 1:07 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/prefs.js ('k') | stats.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/stats.js
===================================================================
--- a/lib/stats.js
+++ b/lib/stats.js
@@ -22,21 +22,17 @@
let {FilterNotifier} = require("filterNotifier");
let badgeColor = "#646464";
-let statsPerPage = new ext.PageMap();
+let blockedPerPage = new ext.PageMap();
/**
- * Get statistics for specified page
- * @param {String} key field key
- * @param {Page} page field page
- * @return {Number} field value
+ * Gets the number of requests blocked on the given page.
+ *
+ * @param {Page} page
+ * @return {Number}
*/
-exports.getStats = function(key, page)
+exports.getBlockedPerPage = function(page)
{
- if (!page)
- return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0);
-
- let pageStats = statsPerPage.get(page);
- return pageStats ? pageStats.blocked : 0;
+ return blockedPerPage.get(page) || 0;
};
FilterNotifier.addListener(function(action, item, newValue, oldValue, page)
@@ -44,36 +40,21 @@
if (action != "filter.hitCount" || !page)
return;
- let blocked = item instanceof BlockingFilter;
+ if (!(item instanceof BlockingFilter))
+ return;
- // Increment counts
- if (blocked)
+ Prefs.blocked_total++;
+
+ let blocked = blockedPerPage.get(page) || 0;
+ blockedPerPage.set(page, ++blocked);
+
+ // Update number in icon
+ if (Prefs.show_statsinicon)
{
- if ("blocked" in Prefs.stats_total)
- Prefs.stats_total.blocked++;
- else
- Prefs.stats_total.blocked = 1;
- Prefs.stats_total = Prefs.stats_total;
-
- let pageStats = statsPerPage.get(page);
- if (!pageStats)
- {
- pageStats = {};
- statsPerPage.set(page, pageStats);
- }
- if ("blocked" in pageStats)
- pageStats.blocked++;
- else
- pageStats.blocked = 1;
-
- // Update number in icon
- if (Prefs.show_statsinicon)
- {
- page.browserAction.setBadge({
- color: badgeColor,
- number: pageStats.blocked
- });
- }
+ page.browserAction.setBadge({
+ color: badgeColor,
+ number: blocked
+ });
}
});
@@ -91,12 +72,12 @@
if (Prefs.show_statsinicon)
{
- let pageStats = statsPerPage.get(page);
- if (pageStats && "blocked" in pageStats)
+ let blocked = blockedPerPage.get(page);
+ if (blocked)
{
badge = {
color: badgeColor,
- number: pageStats.blocked
+ number: blocked
};
}
}
« no previous file with comments | « lib/prefs.js ('k') | stats.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld