Account for optional cache and remove timing code
| @@ -1750,7 +1750,6 @@ export async function getCharacters() { | ||
| 1750 | 1750 | } |
| 1751 | 1751 | |
| 1752 | 1752 | await getGroups(); |
| 1753 | - // clearFuzzySearchCaches(); | |
| 1754 | 1753 | await printCharacters(true); |
| 1755 | 1754 | } |
| 1756 | 1755 | } |
| @@ -1832,25 +1832,21 @@ async function loadContextSettings() { | ||
| 1832 | 1832 | |
| 1833 | 1833 | |
| 1834 | 1834 | /** |
| 1835 | 1835 | * Common function to perform fuzzy search with optional caching |
| 1836 | 1836 | * @param {string} type - Type of search from fuzzySearchCategories |
| 1837 | 1837 | * @param {any[]} data - Data array to search in |
| 1838 | 1838 | * @param {Array<{name: string, weight: number, getFn?: Function}>} keys - Fuse.js keys configuration |
| 1839 | 1839 | * @param {string} searchValue - The search term |
| 1840 | 1840 | * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - FuzzyOptional fuzzy search caches |
| 1841 | 1841 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1842 | 1842 | */ |
| 1843 | 1843 | function performFuzzySearch(type, data, keys, searchValue, fuzzySearchCaches = null) { |
| 1844 | - let startTime = performance.now(); | |
| 1844 | + // Check cache if provided | |
| 1845 | - const cache = fuzzySearchCaches[type]; | |
| 1845 | + if (fuzzySearchCaches) { | |
| 1846 | - | |
| 1846 | + const cache = fuzzySearchCaches[type]; | |
| 1847 | - // Check cache for existing results | |
| 1847 | + if (cache?.resultMap.has(searchValue)) { | |
| 1848 | 1848 | if return (cache.resultMap.hasget(searchValue)) {; |
| 1849 | - let endTime = performance.now(); | |
| 1850 | - if (endTime - startTime > 1.0) { | |
| 1851 | - console.log(`Fuzzy search for ${type} took ${endTime - startTime}ms (cached)`); | |
| 1852 | 1849 | } |
| 1853 | - return cache.resultMap.get(searchValue); | |
| 1854 | 1850 | } |
| 1855 | 1851 | |
| 1856 | 1852 | // @ts-ignore |
| @@ -1863,10 +1859,10 @@ function performFuzzySearch(type, data, keys, searchValue, fuzzySearchCaches) { | ||
| 1863 | 1859 | }); |
| 1864 | 1860 | |
| 1865 | 1861 | const results = fuse.search(searchValue); |
| 1866 | - cache.resultMap.set(searchValue, results); | |
| 1862 | + | |
| 1867 | - let endTime = performance.now(); | |
| 1863 | + // Store in cache if provided | |
| 1868 | 1864 | if (endTime - startTime > 1.0fuzzySearchCaches) { |
| 1869 | - console.log(`Fuzzy search for ${type} took ${endTime - startTime}ms`); | |
| 1865 | + fuzzySearchCaches[type].resultMap.set(searchValue, results); | |
| 1870 | 1866 | } |
| 1871 | 1867 | return results; |
| 1872 | 1868 | } |
| @@ -1874,10 +1870,10 @@ function performFuzzySearch(type, data, keys, searchValue, fuzzySearchCaches) { | ||
| 1874 | 1870 | /** |
| 1875 | 1871 | * Fuzzy search characters by a search term |
| 1876 | 1872 | * @param {string} searchValue - The search term |
| 1877 | 1873 | * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - FuzzyOptional fuzzy search caches |
| 1878 | 1874 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1879 | 1875 | */ |
| 1880 | 1876 | export function fuzzySearchCharacters(searchValue, fuzzySearchCaches = null) { |
| 1881 | 1877 | const keys = [ |
| 1882 | 1878 | { name: 'data.name', weight: 20 }, |
| 1883 | 1879 | { name: '#tags', weight: 10, getFn: (character) => getTagsList(character.avatar).map(x => x.name).join('||') }, |
| @@ -1899,10 +1895,10 @@ export function fuzzySearchCharacters(searchValue, fuzzySearchCaches) { | ||
| 1899 | 1895 | * Fuzzy search world info entries by a search term |
| 1900 | 1896 | * @param {*[]} data - WI items data array |
| 1901 | 1897 | * @param {string} searchValue - The search term |
| 1902 | 1898 | * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - FuzzyOptional fuzzy search caches |
| 1903 | 1899 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1904 | 1900 | */ |
| 1905 | 1901 | export function fuzzySearchWorldInfo(data, searchValue, fuzzySearchCaches = null) { |
| 1906 | 1902 | const keys = [ |
| 1907 | 1903 | { name: 'key', weight: 20 }, |
| 1908 | 1904 | { name: 'group', weight: 15 }, |
| @@ -1920,10 +1916,10 @@ export function fuzzySearchWorldInfo(data, searchValue, fuzzySearchCaches) { | ||
| 1920 | 1916 | * Fuzzy search persona entries by a search term |
| 1921 | 1917 | * @param {*[]} data - persona data array |
| 1922 | 1918 | * @param {string} searchValue - The search term |
| 1923 | 1919 | * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - FuzzyOptional fuzzy search caches |
| 1924 | 1920 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1925 | 1921 | */ |
| 1926 | 1922 | export function fuzzySearchPersonas(data, searchValue, fuzzySearchCaches = null) { |
| 1927 | 1923 | const mappedData = data.map(x => ({ |
| 1928 | 1924 | key: x, |
| 1929 | 1925 | name: power_user.personas[x] ?? '', |
| @@ -1941,10 +1937,10 @@ export function fuzzySearchPersonas(data, searchValue, fuzzySearchCaches) { | ||
| 1941 | 1937 | /** |
| 1942 | 1938 | * Fuzzy search tags by a search term |
| 1943 | 1939 | * @param {string} searchValue - The search term |
| 1944 | 1940 | * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - FuzzyOptional fuzzy search caches |
| 1945 | 1941 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1946 | 1942 | */ |
| 1947 | 1943 | export function fuzzySearchTags(searchValue, fuzzySearchCaches = null) { |
| 1948 | 1944 | const keys = [ |
| 1949 | 1945 | { name: 'name', weight: 1 }, |
| 1950 | 1946 | ]; |
| @@ -1955,10 +1951,10 @@ export function fuzzySearchTags(searchValue, fuzzySearchCaches) { | ||
| 1955 | 1951 | /** |
| 1956 | 1952 | * Fuzzy search groups by a search term |
| 1957 | 1953 | * @param {string} searchValue - The search term |
| 1958 | 1954 | * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - FuzzyOptional fuzzy search caches |
| 1959 | 1955 | * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score |
| 1960 | 1956 | */ |
| 1961 | 1957 | export function fuzzySearchGroups(searchValue, fuzzySearchCaches = null) { |
| 1962 | 1958 | const keys = [ |
| 1963 | 1959 | { name: 'name', weight: 20 }, |
| 1964 | 1960 | { name: 'members', weight: 15 }, |