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

Unified Diff: lib/utils.js

Issue 29562595: Issue 2824 - Only consider ads subscriptions in chooseFilterSubscription (Closed)
Patch Set: Fixed a typo in a comment Created Oct. 3, 2017, 10:14 a.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/subscriptionInit.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/utils.js
diff --git a/lib/utils.js b/lib/utils.js
index e218dab6258ccbecc283e62c3d27c155cf973774..04327602e3708010fd4d04816b005d4af5eb5cd3 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -65,59 +65,6 @@ let Utils = exports.Utils = {
// We cannot calculate MD5 checksums yet :-(
return null;
},
- checkLocalePrefixMatch(prefixes)
- {
- if (!prefixes)
- return null;
-
- for (let prefix of prefixes.split(","))
- {
- if (new RegExp("^" + prefix + "\\b").test(this.appLocale))
- return prefix;
- }
-
- return null;
- },
-
- chooseFilterSubscription(subscriptions)
- {
- let selectedItem = null;
- let selectedPrefix = null;
- let matchCount = 0;
- for (let subscription of subscriptions)
- {
- if (!selectedItem)
- selectedItem = subscription;
-
- let prefix = Utils.checkLocalePrefixMatch(
- subscription.getAttribute("prefixes")
- );
- if (prefix)
- {
- if (!selectedPrefix || selectedPrefix.length < prefix.length)
- {
- selectedItem = subscription;
- selectedPrefix = prefix;
- matchCount = 1;
- }
- else if (selectedPrefix && selectedPrefix.length == prefix.length)
- {
- matchCount++;
-
- // If multiple items have a matching prefix of the same length:
- // Select one of the items randomly, probability should be the same
- // for all items. So we replace the previous match here with
- // probability 1/N (N being the number of matches).
- if (Math.random() * matchCount < 1)
- {
- selectedItem = subscription;
- selectedPrefix = prefix;
- }
- }
- }
- }
- return selectedItem;
- },
getDocLink(linkID)
{
« no previous file with comments | « lib/subscriptionInit.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld