Rewild Your Web
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

search: improve responsivness (maybe\!)

Signed-off-by: webbeef <me@webbeef.org>

+26 -23
+15 -8
ui/shared/search/controller.js
··· 46 46 // Current results 47 47 this.results = []; 48 48 this.groups = []; 49 + this.queryGeneration = 0; 49 50 50 51 // Create debounced query function 51 52 this.debouncedQuery = debounce( ··· 66 67 * Query immediately without debouncing 67 68 * @param {string} query - The search query 68 69 */ 69 - async queryImmediate(query) { 70 - await this.executeQuery(query.trim()); 70 + queryImmediate(query) { 71 + this.executeQuery(query.trim()); 71 72 } 72 73 73 74 /** 74 75 * Execute the query and update results 75 76 * @private 76 77 */ 77 - async executeQuery(query) { 78 - this.results = await this.aggregator.query(query); 79 - this.groups = groupResults(this.results); 78 + executeQuery(query) { 79 + const generation = ++this.queryGeneration; 80 80 81 - if (this.onResultsChanged) { 82 - this.onResultsChanged(this.results, this.groups); 83 - } 81 + this.aggregator.query(query, (results) => { 82 + if (generation !== this.queryGeneration) { 83 + return; 84 + } 85 + this.results = results; 86 + this.groups = groupResults(results); 87 + if (this.onResultsChanged) { 88 + this.onResultsChanged(this.results, this.groups); 89 + } 90 + }); 84 91 } 85 92 86 93 /**
+11 -15
ui/system/results_aggregator.js
··· 15 15 this.providers = this.providers.filter((p) => p.name !== name); 16 16 } 17 17 18 - // Query all providers in parallel and return sorted results 19 - async query(text) { 20 - const promises = this.providers.map(async (provider) => { 18 + // Query all providers in parallel, calling onUpdate as each resolves 19 + query(text, onUpdate) { 20 + const results = []; 21 + 22 + this.providers.map(async (provider) => { 21 23 try { 22 - const results = await provider.query(text); 23 - // Tag results with provider name and icon 24 - return results.map((r) => ({ 24 + const providerResults = await provider.query(text); 25 + const tagged = providerResults.map((r) => ({ 25 26 ...r, 26 27 provider: provider.name, 27 28 providerIcon: provider.icon, 28 29 })); 30 + results.push(...tagged); 31 + results.sort((a, b) => (b.score || 0) - (a.score || 0)); 32 + console.log(`Updating results from ${provider.name}`); 33 + onUpdate(results); 29 34 } catch (e) { 30 35 console.error(`Provider ${provider.name} error:`, e); 31 - return []; 32 36 } 33 37 }); 34 - 35 - const resultsArrays = await Promise.all(promises); 36 - const allResults = resultsArrays.flat(); 37 - 38 - // Sort by score (descending), defaulting to 0 if not set 39 - allResults.sort((a, b) => (b.score || 0) - (a.score || 0)); 40 - 41 - return allResults; 42 38 } 43 39 }