thanhnguyen2187 / crypta

An offline-first code snippet manager
https://thanhnguyen2187.github.io/crypta/
MIT License
7 stars 0 forks source link

Tag filtering and search input filtering performance concern #12

Closed thanhnguyen2187 closed 9 months ago

thanhnguyen2187 commented 9 months ago

Would it work if there is a lot of data?

export const displaySnippetsStore = derived(
  [localSnippetStore, globalTagsStore, globalSearchStore],
  ([localSnippets, globalTags, globalSearch]) => {
    globalSearch = globalSearch.toLowerCase()
    const filteredSnippets = localSnippets.filter(
      snippet => {
        const snippetTags = new Set(snippet.tags)
        const searchingFound =
          snippet.name.toLowerCase().includes(globalSearch) ||
          snippet.text.toLowerCase().includes(globalSearch)
        // make sure that the snippet's tags include every global tag
        const taggingFound = Array
          .from(globalTags.keys())
          .every(globalTag => snippetTags.has(globalTag))
        return searchingFound && taggingFound
      }
    )
    return filteredSnippets
  }
)
thanhnguyen2187 commented 9 months ago

Should not be a problem after #26.