Sped up character search by 93%
| @@ -330,6 +330,12 @@ const debug_functions = []; | ||
| 330 | 330 | |
| 331 | 331 | const setHotswapsDebounced = debounce(favsToHotswap); |
| 332 | 332 | |
| 333 | +const fuzzySearchCharactersCache = new Map(); | |
| 334 | +const fuzzySearchWorldInfoCache = new Map(); | |
| 335 | +const fuzzySearchPersonasCache = new Map(); | |
| 336 | +const fuzzySearchTagsCache = new Map(); | |
| 337 | +const fuzzySearchGroupsCache = new Map(); | |
| 338 | + | |
| 333 | 339 | function playMessageSound() { |
| 334 | 340 | if (!power_user.play_message_sound) { |
| 335 | 341 | return; |
| @@ -1830,6 +1836,11 @@ async function loadContextSettings() { | ||
| 1830 | 1836 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1831 | 1837 | */ |
| 1832 | 1838 | export function fuzzySearchCharacters(searchValue) { |
| 1839 | + | |
| 1840 | + if (fuzzySearchCharactersCache.has(searchValue)) { | |
| 1841 | + return fuzzySearchCharactersCache.get(searchValue); | |
| 1842 | + } | |
| 1843 | + | |
| 1833 | 1844 | // @ts-ignore |
| 1834 | 1845 | const fuse = new Fuse(characters, { |
| 1835 | 1846 | keys: [ |
| @@ -1853,6 +1864,7 @@ export function fuzzySearchCharacters(searchValue) { | ||
| 1853 | 1864 | |
| 1854 | 1865 | const results = fuse.search(searchValue); |
| 1855 | 1866 | console.debug('Characters fuzzy search results for ' + searchValue, results); |
| 1867 | + fuzzySearchCharactersCache.set(searchValue, results); | |
| 1856 | 1868 | return results; |
| 1857 | 1869 | } |
| 1858 | 1870 | |
| @@ -1863,6 +1875,10 @@ export function fuzzySearchCharacters(searchValue) { | ||
| 1863 | 1875 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1864 | 1876 | */ |
| 1865 | 1877 | export function fuzzySearchWorldInfo(data, searchValue) { |
| 1878 | + if (fuzzySearchWorldInfoCache.has(searchValue)) { | |
| 1879 | + return fuzzySearchWorldInfoCache.get(searchValue); | |
| 1880 | + } | |
| 1881 | + | |
| 1866 | 1882 | // @ts-ignore |
| 1867 | 1883 | const fuse = new Fuse(data, { |
| 1868 | 1884 | keys: [ |
| @@ -1882,6 +1898,7 @@ export function fuzzySearchWorldInfo(data, searchValue) { | ||
| 1882 | 1898 | |
| 1883 | 1899 | const results = fuse.search(searchValue); |
| 1884 | 1900 | console.debug('World Info fuzzy search results for ' + searchValue, results); |
| 1901 | + fuzzySearchWorldInfoCache.set(searchValue, results); | |
| 1885 | 1902 | return results; |
| 1886 | 1903 | } |
| 1887 | 1904 | |
| @@ -1892,6 +1909,10 @@ export function fuzzySearchWorldInfo(data, searchValue) { | ||
| 1892 | 1909 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1893 | 1910 | */ |
| 1894 | 1911 | export function fuzzySearchPersonas(data, searchValue) { |
| 1912 | + if (fuzzySearchPersonasCache.has(searchValue)) { | |
| 1913 | + return fuzzySearchPersonasCache.get(searchValue); | |
| 1914 | + } | |
| 1915 | + | |
| 1895 | 1916 | data = data.map(x => ({ key: x, name: power_user.personas[x] ?? '', description: power_user.persona_descriptions[x]?.description ?? '' })); |
| 1896 | 1917 | // @ts-ignore |
| 1897 | 1918 | const fuse = new Fuse(data, { |
| @@ -1907,6 +1928,7 @@ export function fuzzySearchPersonas(data, searchValue) { | ||
| 1907 | 1928 | |
| 1908 | 1929 | const results = fuse.search(searchValue); |
| 1909 | 1930 | console.debug('Personas fuzzy search results for ' + searchValue, results); |
| 1931 | + fuzzySearchPersonasCache.set(searchValue, results); | |
| 1910 | 1932 | return results; |
| 1911 | 1933 | } |
| 1912 | 1934 | |
| @@ -1916,6 +1938,10 @@ export function fuzzySearchPersonas(data, searchValue) { | ||
| 1916 | 1938 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1917 | 1939 | */ |
| 1918 | 1940 | export function fuzzySearchTags(searchValue) { |
| 1941 | + if (fuzzySearchTagsCache.has(searchValue)) { | |
| 1942 | + return fuzzySearchTagsCache.get(searchValue); | |
| 1943 | + } | |
| 1944 | + | |
| 1919 | 1945 | // @ts-ignore |
| 1920 | 1946 | const fuse = new Fuse(tags, { |
| 1921 | 1947 | keys: [ |
| @@ -1929,6 +1955,7 @@ export function fuzzySearchTags(searchValue) { | ||
| 1929 | 1955 | |
| 1930 | 1956 | const results = fuse.search(searchValue); |
| 1931 | 1957 | console.debug('Tags fuzzy search results for ' + searchValue, results); |
| 1958 | + fuzzySearchTagsCache.set(searchValue, results); | |
| 1932 | 1959 | return results; |
| 1933 | 1960 | } |
| 1934 | 1961 | |
| @@ -1938,6 +1965,10 @@ export function fuzzySearchTags(searchValue) { | ||
| 1938 | 1965 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1939 | 1966 | */ |
| 1940 | 1967 | export function fuzzySearchGroups(searchValue) { |
| 1968 | + if (fuzzySearchGroupsCache.has(searchValue)) { | |
| 1969 | + return fuzzySearchGroupsCache.get(searchValue); | |
| 1970 | + } | |
| 1971 | + | |
| 1941 | 1972 | // @ts-ignore |
| 1942 | 1973 | const fuse = new Fuse(groups, { |
| 1943 | 1974 | keys: [ |
| @@ -1954,6 +1985,7 @@ export function fuzzySearchGroups(searchValue) { | ||
| 1954 | 1985 | |
| 1955 | 1986 | const results = fuse.search(searchValue); |
| 1956 | 1987 | console.debug('Groups fuzzy search results for ' + searchValue, results); |
| 1988 | + fuzzySearchGroupsCache.set(searchValue, results); | |
| 1957 | 1989 | return results; |
| 1958 | 1990 | } |
| 1959 | 1991 | |