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: Rebased to e2203d4fd258 Created Jan. 29, 2018, 12:44 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
@@ -102,12 +102,25 @@
return -1;
}
+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 = () => {};
+ notification._matcher = matcher;
+}
+
/**
* The object providing actual downloading functionality.
* @type {Downloader}
*/
let downloader = null;
let localData = [];
+let remoteData = [];
/**
* Regularly fetches notifications and decides which to show.
@@ -120,6 +133,14 @@
*/
init()
{
+ 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);
downloader.onExpirationChange = this._onExpirationChange.bind(this);
@@ -174,7 +195,9 @@
notification.type = notification.severity;
delete notification.severity;
}
+ initNotificationMatcher(notification);
}
+ remoteData = data.notifications;
Prefs.notificationdata.data = data;
}
catch (e)
@@ -233,13 +256,6 @@
*/
_getNextToShow(url)
{
- let remoteData = [];
- if (typeof Prefs.notificationdata.data == "object" &&
- Prefs.notificationdata.data.notifications instanceof Array)
- {
- remoteData = Prefs.notificationdata.data.notifications;
- }
-
let notifications = localData.concat(remoteData);
if (notifications.length === 0)
return null;
@@ -298,10 +314,10 @@
}
}
- if (typeof url === "string" || notification.urlFilters instanceof Array)
+ if (typeof url === "string" || "_matcher" in notification)
Thomas Greiner 2018/01/29 15:39:20 This block contains relevant changes that were mad
{
if (Prefs.enabled && typeof url === "string" &&
- notification.urlFilters instanceof Array)
+ "_matcher" in notification)
{
let host;
try
@@ -319,14 +335,9 @@
if (exception instanceof WhitelistFilter)
continue;
- let matcher = new Matcher();
- for (let urlFilter of notification.urlFilters)
- matcher.add(Filter.fromText(urlFilter));
- if (!matcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, host,
- false, null))
- {
+ if (!notification._matcher.matchesAny(url,
+ RegExpFilter.typeMap.DOCUMENT, host, false, null))
continue;
- }
}
else
continue;
@@ -433,7 +444,10 @@
addNotification(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