Bug 1361480 - Improve logic for size related filters; r=gasolin
authorJan Odvarko <odvarko@gmail.com>
Wed, 03 May 2017 08:27:35 +0200
changeset 573118 579a36c00c58d6175932905a8f4c2260ad2c1989
parent 573117 4ec64c93ac17d3aeae1b53b39e13a982f572cb70
child 573119 366d1dc1f33e55c6b4c93c1ef0ebe4834c3c9df6
push id57306
push userbmo:emilio+bugs@crisal.io
push dateFri, 05 May 2017 10:08:55 +0000
reviewersgasolin
bugs1361480
milestone55.0a1
Bug 1361480 - Improve logic for size related filters; r=gasolin MozReview-Commit-ID: 5hA6kpG9OhA
devtools/client/netmonitor/src/utils/filter-text-utils.js
--- a/devtools/client/netmonitor/src/utils/filter-text-utils.js
+++ b/devtools/client/netmonitor/src/utils/filter-text-utils.js
@@ -111,20 +111,16 @@ function processFlagFilter(type, value) 
         return null;
       }
       return quantity * multiplier;
     default:
       return value.toLowerCase();
   }
 }
 
-function getSizeOrder(size) {
-  return Math.round(Math.log10(size));
-}
-
 function isFlagFilterMatch(item, { type, value, negative }) {
   let match = true;
   let { responseCookies = { cookies: [] } } = item;
   responseCookies = responseCookies.cookies || responseCookies;
   switch (type) {
     case "status-code":
       match = item.status === value;
       break;
@@ -155,21 +151,21 @@ function isFlagFilterMatch(item, { type,
       let causeType = item.cause.type;
       match = typeof causeType === "string" ?
                 causeType.toLowerCase().includes(value) : false;
       break;
     case "transferred":
       if (item.fromCache) {
         match = false;
       } else {
-        match = getSizeOrder(value) === getSizeOrder(item.transferredSize);
+        match = isSizeMatch(value, item.transferredSize);
       }
       break;
     case "size":
-      match = getSizeOrder(value) === getSizeOrder(item.contentSize);
+      match = isSizeMatch(value, item.contentSize);
       break;
     case "larger-than":
       match = item.contentSize > value;
       break;
     case "mime-type":
       match = item.mimeType.includes(value);
       break;
     case "is":
@@ -211,16 +207,20 @@ function isFlagFilterMatch(item, { type,
       break;
   }
   if (negative) {
     return !match;
   }
   return match;
 }
 
+function isSizeMatch(value, size) {
+  return value >= (size - size / 10) && value < (size + size / 10);
+}
+
 function isTextFilterMatch({ url }, text) {
   let lowerCaseUrl = url.toLowerCase();
   let lowerCaseText = text.toLowerCase();
   let textLength = text.length;
   // Support negative filtering
   if (text.startsWith("-") && textLength > 1) {
     lowerCaseText = lowerCaseText.substring(1, textLength);
     return !lowerCaseUrl.includes(lowerCaseText);