thanhnguyen2187 / crypta

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

Recheck memory leaking of store subscription #49

Open thanhnguyen2187 opened 7 months ago

thanhnguyen2187 commented 7 months ago

On src/lib/utilities/persistence.ts, there is createLocalSnippetStoreV2 which uses .subscribe without subscription:

  stores.subscribe(
    // TODO: fix the typing of `globalState` and `migrationState`, which both
    //       have the type `GlobalState | MigrationState`
    async ([globalState, migrationState]) => {
      if (migrationState === 'done') {
        const dbSnippets = await querySnippetsByFolderId(db, folderId)
        const snippetIds = dbSnippets.map(snippet => snippet.id)
        const tags = await queryTagsBySnippetIds(db, snippetIds)
        const tagsMap = buildTagsMap(tags)
        snippets = dbSnippets.map(
          (dbSnippet) => dbSnippetToDisplaySnippet(dbSnippet, tagsMap)
        )
        store.set(snippets)
      }
    }
  )

We should check other places as well.