forked from MapComplete/MapComplete
		
	Search: fix slow search on home screen
This commit is contained in:
		
							parent
							
								
									644552b88d
								
							
						
					
					
						commit
						2db7ef872c
					
				
					 1 changed files with 13 additions and 11 deletions
				
			
		|  | @ -10,7 +10,7 @@ | ||||||
|   import LoginToggle from "./Base/LoginToggle.svelte" |   import LoginToggle from "./Base/LoginToggle.svelte" | ||||||
|   import Pencil from "../assets/svg/Pencil.svelte" |   import Pencil from "../assets/svg/Pencil.svelte" | ||||||
|   import Constants from "../Models/Constants" |   import Constants from "../Models/Constants" | ||||||
|   import { Store, Stores, UIEventSource } from "../Logic/UIEventSource" |   import { ImmutableStore, Store, Stores, UIEventSource } from "../Logic/UIEventSource" | ||||||
|   import ThemesList from "./BigComponents/ThemesList.svelte" |   import ThemesList from "./BigComponents/ThemesList.svelte" | ||||||
|   import { MinimalLayoutInformation } from "../Models/ThemeConfig/LayoutConfig" |   import { MinimalLayoutInformation } from "../Models/ThemeConfig/LayoutConfig" | ||||||
|   import Eye from "../assets/svg/Eye.svelte" |   import Eye from "../assets/svg/Eye.svelte" | ||||||
|  | @ -22,9 +22,9 @@ | ||||||
|   import { Utils } from "../Utils" |   import { Utils } from "../Utils" | ||||||
|   import { ArrowTrendingUp } from "@babeard/svelte-heroicons/solid/ArrowTrendingUp" |   import { ArrowTrendingUp } from "@babeard/svelte-heroicons/solid/ArrowTrendingUp" | ||||||
|   import Searchbar from "./Base/Searchbar.svelte" |   import Searchbar from "./Base/Searchbar.svelte" | ||||||
|   import ChevronDoubleRight from "@babeard/svelte-heroicons/mini/ChevronDoubleRight" |  | ||||||
|   import ThemeSearch from "../Logic/Search/ThemeSearch" |   import ThemeSearch from "../Logic/Search/ThemeSearch" | ||||||
|   import SearchUtils from "../Logic/Search/SearchUtils" |   import SearchUtils from "../Logic/Search/SearchUtils" | ||||||
|  |   import ChevronDoubleRight from "@babeard/svelte-heroicons/mini/ChevronDoubleRight" | ||||||
| 
 | 
 | ||||||
|   const featureSwitches = new OsmConnectionFeatureSwitches() |   const featureSwitches = new OsmConnectionFeatureSwitches() | ||||||
|   const osmConnection = new OsmConnection({ |   const osmConnection = new OsmConnection({ | ||||||
|  | @ -54,26 +54,28 @@ | ||||||
|   const customThemes: Store<MinimalLayoutInformation[]> = Stores.ListStabilized<string>(state.installedUserThemes) |   const customThemes: Store<MinimalLayoutInformation[]> = Stores.ListStabilized<string>(state.installedUserThemes) | ||||||
|     .mapD(stableIds => Utils.NoNullInplace(stableIds.map(id => state.getUnofficialTheme(id)))) |     .mapD(stableIds => Utils.NoNullInplace(stableIds.map(id => state.getUnofficialTheme(id)))) | ||||||
| 
 | 
 | ||||||
|   function filtered(themes: MinimalLayoutInformation[]): Store<MinimalLayoutInformation[]> { |   function filtered(themes: Store<MinimalLayoutInformation[]>): Store<MinimalLayoutInformation[]> { | ||||||
|     const prefiltered = themes.filter(th => th.id !== "personal") |  | ||||||
|     return searchStable.map(search => { |     return searchStable.map(search => { | ||||||
|       if (!search) { |       if (!search) { | ||||||
|         return themes |         return themes.data | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       const scores = ThemeSearch.sortedByLowestScores(search, prefiltered) |       const start = new Date().getTime() | ||||||
|  |       const scores = ThemeSearch.sortedByLowestScores(search, themes.data) | ||||||
|  |       const end = new Date().getTime() | ||||||
|  |       console.trace("Scores for", search , "are", scores, "searching took", end - start,"ms") | ||||||
|       const strict = scores.filter(sc => sc.lowest < 2) |       const strict = scores.filter(sc => sc.lowest < 2) | ||||||
|       if (strict.length > 0) { |       if (strict.length > 0) { | ||||||
|         return strict.map(sc => sc.theme) |         return strict.map(sc => sc.theme) | ||||||
|       } |       } | ||||||
|       return scores.filter(sc => sc.lowest < 4).slice(0, 6).map(sc => sc.theme) |       return scores.filter(sc => sc.lowest < 4).slice(0, 6).map(sc => sc.theme) | ||||||
|     }) |     }, [themes]) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   let officialSearched = filtered(officialThemes) |   let officialSearched : Store<MinimalLayoutInformation[]>= filtered(new ImmutableStore(officialThemes)) | ||||||
|   let hiddenSearched = visitedHiddenThemes.bindD(visited => filtered(visited)) |   let hiddenSearched: Store<MinimalLayoutInformation[]> =  filtered(visitedHiddenThemes) | ||||||
|   let customSearched = customThemes.bindD(customThemes => filtered(customThemes)) |   let customSearched: Store<MinimalLayoutInformation[]> = filtered(customThemes) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   let searchIsFocussed = new UIEventSource(false) |   let searchIsFocussed = new UIEventSource(false) | ||||||
|  | @ -133,7 +135,7 @@ | ||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|     <Searchbar value={search} placeholder={tr.searchForATheme} on:search={() => applySearch()} isFocused={searchIsFocussed} /> |     <Searchbar value={search} placeholder={tr.searchForATheme} on:search={() => applySearch()}  /> | ||||||
| 
 | 
 | ||||||
|     <ThemesList {search} {state} themes={$officialSearched} /> |     <ThemesList {search} {state} themes={$officialSearched} /> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue