Bug 1544530 - [sync 132] - Limit resultCount in QuickOpenModal to 100 sources r=jlast
authorAlex Rosenfeld <arosenfeld2003@mac.com>
Tue, 16 Apr 2019 16:52:25 +0000
changeset 469771 4f6f63643ad2
parent 469770 4b2f5b362c25
child 469772 fb9539c87371
push id35882
push usercbrindusan@mozilla.com
push dateWed, 17 Apr 2019 15:54:01 +0000
treeherdermozilla-central@37185c0ae520 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1544530
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1544530 - [sync 132] - Limit resultCount in QuickOpenModal to 100 sources r=jlast Differential Revision: https://phabricator.services.mozilla.com/D27715
devtools/client/debugger/src/components/QuickOpenModal.js
devtools/client/debugger/src/components/test/QuickOpenModal.spec.js
--- a/devtools/client/debugger/src/components/QuickOpenModal.js
+++ b/devtools/client/debugger/src/components/QuickOpenModal.js
@@ -66,29 +66,38 @@ type State = {
 };
 
 type GotoLocationType = {
   sourceId?: string,
   line: number,
   column?: number
 };
 
+const maxResults = 100;
+
 function filter(values, query) {
   return fuzzyAldrin.filter(values, query, {
     key: "value",
-    maxResults: 1000
+    maxResults: maxResults
   });
 }
 
 export class QuickOpenModal extends Component<Props, State> {
   constructor(props: Props) {
     super(props);
     this.state = { results: null, selectedIndex: 0 };
   }
 
+  setResults(results: ?Array<QuickOpenResult>) {
+    if (results) {
+      results = results.slice(0, maxResults);
+    }
+    this.setState({ results });
+  }
+
   componentDidMount() {
     const { query, shortcutsModalEnabled, toggleShortcutsModal } = this.props;
 
     this.updateResults(query);
 
     if (shortcutsModalEnabled) {
       toggleShortcutsModal();
     }
@@ -118,53 +127,50 @@ export class QuickOpenModal extends Comp
   dropGoto = (query: string) => {
     return query.split(":")[0];
   };
 
   searchSources = (query: string) => {
     const { sources } = this.props;
     const results =
       query == "" ? sources : filter(sources, this.dropGoto(query));
-    return this.setState({ results });
+    return this.setResults(results);
   };
 
   searchSymbols = (query: string) => {
     const {
       symbols: { functions }
     } = this.props;
 
     let results = functions;
     results = results.filter(result => result.title !== "anonymous");
 
     if (query === "@" || query === "#") {
-      return this.setState({ results });
+      return this.setResults(results);
     }
-
-    this.setState({ results: filter(results, query.slice(1)) });
+    results = filter(results, query.slice(1));
+    return this.setResults(results);
   };
 
   searchShortcuts = (query: string) => {
     const results = formatShortcutResults();
     if (query == "?") {
-      this.setState({ results });
+      this.setResults(results);
     } else {
-      this.setState({ results: filter(results, query.slice(1)) });
+      this.setResults(filter(results, query.slice(1)));
     }
   };
 
   showTopSources = () => {
     const { tabs, sources } = this.props;
     if (tabs.length > 0) {
       const tabUrls = tabs.map((tab: Tab) => tab.url);
-
-      this.setState({
-        results: sources.filter(source => tabUrls.includes(source.url))
-      });
+      this.setResults(sources.filter(source => tabUrls.includes(source.url)));
     } else {
-      this.setState({ results: sources.slice(0, 100) });
+      this.setResults(sources);
     }
   };
 
   updateResults = (query: string) => {
     if (this.isGotoQuery()) {
       return;
     }
 
@@ -371,18 +377,17 @@ export class QuickOpenModal extends Comp
 
   render() {
     const { enabled, query } = this.props;
     const { selectedIndex, results } = this.state;
 
     if (!enabled) {
       return null;
     }
-    const newResults = results && results.slice(0, 100);
-    const items = this.highlightMatching(query, newResults || []);
+    const items = this.highlightMatching(query, results || []);
     const expanded = !!items && items.length > 0;
 
     return (
       <Modal in={enabled} handleClose={this.closeModal}>
         <SearchInput
           query={query}
           hasPrefix={true}
           count={this.getResultCount()}
@@ -395,17 +400,17 @@ export class QuickOpenModal extends Comp
           handleClose={this.closeModal}
           expanded={expanded}
           showClose={false}
           selectedItemId={
             expanded && items[selectedIndex] ? items[selectedIndex].id : ""
           }
           {...(this.isSourceSearch() ? { size: "big" } : {})}
         />
-        {newResults && (
+        {results && (
           <ResultList
             key="results"
             items={items}
             selected={selectedIndex}
             selectItem={this.selectResultItem}
             ref="resultList"
             expanded={expanded}
             {...(this.isSourceSearch() ? { size: "big" } : {})}
--- a/devtools/client/debugger/src/components/test/QuickOpenModal.spec.js
+++ b/devtools/client/debugger/src/components/test/QuickOpenModal.spec.js
@@ -206,17 +206,17 @@ describe("QuickOpenModal", () => {
           variables: []
         }
       },
       "mount"
     );
     wrapper.find("input").simulate("change", { target: { value: "somefil" } });
     expect(filter).toHaveBeenCalledWith([], "somefil", {
       key: "value",
-      maxResults: 1000
+      maxResults: 100
     });
   });
 
   test("basic gotoSource search", () => {
     const { wrapper } = generateModal(
       {
         enabled: true,
         searchType: "gotoSource",
@@ -227,17 +227,17 @@ describe("QuickOpenModal", () => {
       },
       "mount"
     );
     wrapper
       .find("input")
       .simulate("change", { target: { value: "somefil:33" } });
     expect(filter).toHaveBeenCalledWith([], "somefil", {
       key: "value",
-      maxResults: 1000
+      maxResults: 100
     });
   });
 
   describe("empty symbol search", () => {
     it("basic symbol search", () => {
       const { wrapper } = generateModal(
         {
           enabled: true,
@@ -254,17 +254,17 @@ describe("QuickOpenModal", () => {
       );
 
       wrapper
         .find("input")
         .simulate("change", { target: { value: "@someFunc" } });
 
       expect(filter).toHaveBeenCalledWith([], "someFunc", {
         key: "value",
-        maxResults: 1000
+        maxResults: 100
       });
     });
 
     it("does not do symbol search if no selected source", () => {
       const { wrapper } = generateModal(
         {
           enabled: true,
           searchType: "functions",