on master help sign in
Merge pull request #1624 from urbit/mp/parallel

search: parallelisation

commit6c36379c4a68270ecaad9271b71e3e5f01092177 authormatildepark <matilde.park@urbit.org> dateWed 6 Jul 2022, 19:01 (4 years ago) parent9c41a3ac666bca
1 file changed+54−52
components/Search.js+54−52
components/Search.js+54−52
@@ -60,70 +60,72 @@ class Search extends Component {
6060
6161 onInputValueChange = debounce(async (query) => {
6262 if (query.length) {
63− fetch(this.searchEndpoint(query))
63+ const search = fetch(this.searchEndpoint(query))
6464 .then((res) => res.json())
6565 .then(async (res) => {
66− // Wrap results in an object which will tell React what component to use to render results.
67− const results = res.results.map((item) => ({
66+ return res.results.map((item) => ({
6867 type: "RESULT",
6968 content: item,
7069 }));
70+ });
7171
72− const patp = this.patpSearch(query)
73− ? !isNaN(query)
74− ? ob.patp(query)
75− : ob.patp(ob.patp2dec(`~${deSig(query)}`))
76− : null;
72+ const patp = this.patpSearch(query)
73+ ? !isNaN(query)
74+ ? ob.patp(query)
75+ : ob.patp(ob.patp2dec(`~${deSig(query)}`))
76+ : null;
7777
78− const patpResult = this.patpSearch(query)
79− ? [
80− {
81− type: "PATP",
82− content: {
83− patp: patp,
84− slug: `/ids/${patp}`,
85− },
86− },
87− ]
88− : [];
78+ const patpResult = this.patpSearch(query)
79+ ? [
80+ {
81+ type: "PATP",
82+ content: {
83+ patp: patp,
84+ slug: `/ids/${patp}`,
85+ },
86+ },
87+ ]
88+ : [];
8989
90− const glossaryResults = await fetch(this.glossarySearch(query))
91− .then((res) => res.json())
92− .then((res) => {
93− return res.results.map((item) => ({
94− type: "GLOSSARY_RESULT",
95− content: item,
96− }));
97− });
90+ const glossarySearch = fetch(this.glossarySearch(query))
91+ .then((res) => res.json())
92+ .then((res) => {
93+ return res.results.map((item) => ({
94+ type: "GLOSSARY_RESULT",
95+ content: item,
96+ }));
97+ });
9898
99− const devResults = await fetch(this.devSearch(query))
100− .then((res) => res.json())
101− .then((res) => {
102− return res.results.map((item) => ({
103− type: "DEV_RESULT",
104− content: item,
105− }));
106− });
99+ const devSearch = fetch(this.devSearch(query))
100+ .then((res) => res.json())
101+ .then((res) => {
102+ return res.results.map((item) => ({
103+ type: "DEV_RESULT",
104+ content: item,
105+ }));
106+ });
107107
108− const opsResults = await fetch(this.opsSearch(query))
109− .then((res) => res.json())
110− .then((res) => {
111− return res.results.map((item) => ({
112− type: "OPS_RESULT",
113− content: item,
114− }));
115− });
108+ const opsSearch = fetch(this.opsSearch(query))
109+ .then((res) => res.json())
110+ .then((res) => {
111+ return res.results.map((item) => ({
112+ type: "OPS_RESULT",
113+ content: item,
114+ }));
115+ });
116116
117− const list = [
118− ...glossaryResults,
119− ...patpResult,
120− ...results,
121− ...devResults,
122− ...opsResults,
123− ];
117+ const [results, glossaryResults, devResults, opsResults] =
118+ await Promise.all([search, glossarySearch, devSearch, opsSearch]);
124119
125− this.setState({ results: list });
126− });
120+ const list = [
121+ ...glossaryResults,
122+ ...patpResult,
123+ ...results,
124+ ...devResults,
125+ ...opsResults,
126+ ];
127+
128+ this.setState({ results: list });
127129 } else {
128130 this.setState({ results: [] });
129131 }