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

Unified Diff: lib/notification.js

Issue 5330039625220096: Issue 1162 - Cache notification URL matcher
Patch Set: Created Oct. 23, 2014, 2:09 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notification.js
===================================================================
--- a/lib/notification.js
+++ b/lib/notification.js
@@ -62,12 +62,25 @@
return translations[defaultLocale];
}
+function initNotificationMatcher(notification)
+{
+ if ("_matcher" in notification || !(notification.urlFilters instanceof Array))
+ return;
+
+ let matcher = new Matcher();
+ for (let urlFilter of notification.urlFilters)
+ matcher.add(Filter.fromText(urlFilter));
+ matcher.toJSON = () => {};
sergei 2018/01/03 11:12:22 This is not exactly how it's said in the issue "No
Thomas Greiner 2018/01/11 18:18:19 Fortunately, we can now use `Symbol` instead so th
kzar 2018/01/12 12:27:17 Acknowledged.
+ notification._matcher = matcher;
+}
+
/**
* The object providing actual downloading functionality.
* @type Downloader
*/
let downloader = null;
let localData = [];
+let remoteData = [];
sergei 2018/01/03 11:12:22 Could you please add a comment that localData and
Thomas Greiner 2018/01/11 18:18:19 Yep, will do.
/**
* Regularly fetches notifications and decides which to show.
@@ -80,6 +93,14 @@
*/
init: function()
{
+ let notificationdata = Prefs.notificationdata.data;
+ if (notificationdata)
+ {
+ for (let notification of notificationdata.notifications)
+ initNotificationMatcher(notification);
+ remoteData = notificationdata.notifications;
+ }
+
downloader = new Downloader(this._getDownloadables.bind(this), INITIAL_DELAY, CHECK_INTERVAL);
onShutdown.add(function()
{
@@ -131,7 +152,9 @@
notification.type = notification.severity;
delete notification.severity;
}
+ initNotificationMatcher(notification);
}
+ remoteData = data.notifications;
sergei 2018/01/03 11:12:22 It's a bit theoretical but IMO it can be a technic
kzar 2018/01/04 17:04:09 Yea, I don't think these changes are necessary now
Thomas Greiner 2018/01/11 18:18:19 Good point. I don't remember why I made this chang
Prefs.notificationdata.data = data;
sergei 2018/01/03 11:12:22 Despite it's not directly a part of this issue, sh
kzar 2018/01/04 17:04:09 Hmm, I'm not too familiar with this code but I thi
Thomas Greiner 2018/01/11 18:18:19 By overriding existing notifications we can contro
}
catch (e)
@@ -170,10 +193,6 @@
(maxVersionKey in target && Services.vc.compare(version, target[maxVersionKey]) > 0));
}
- let remoteData = [];
- if (typeof Prefs.notificationdata.data == "object" && Prefs.notificationdata.data.notifications instanceof Array)
- remoteData = Prefs.notificationdata.data.notifications;
-
if (!(Prefs.notificationdata.shown instanceof Array))
{
Prefs.notificationdata.shown = [];
@@ -192,14 +211,11 @@
&& Prefs.notificationdata.shown.indexOf(notification.id) !== -1)
kzar 2018/01/04 17:04:09 We can use .includes(notification.id) these days (
continue;
- if (typeof url === "string" || notification.urlFilters instanceof Array)
kzar 2018/01/04 17:04:09 IMO this code should instead be replaced with a ca
Thomas Greiner 2018/01/11 18:18:19 I agree that splitting that off into its own funct
kzar 2018/01/12 12:27:17 Acknowledged.
+ if (typeof url === "string" || "_matcher" in notification)
{
- if (typeof url === "string" && notification.urlFilters instanceof Array)
+ if (typeof url === "string" && "_matcher" in notification)
{
- let matcher = new Matcher();
- for (let urlFilter of notification.urlFilters)
- matcher.add(Filter.fromText(urlFilter));
- if (!matcher.matchesAny(url, "DOCUMENT", url))
+ if (!notification._matcher.matchesAny(url, "DOCUMENT", url))
continue;
}
else
@@ -278,7 +294,10 @@
addNotification: function(notification)
{
if (localData.indexOf(notification) == -1)
+ {
+ initNotificationMatcher(notification);
localData.push(notification);
+ }
},
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld