Avoid calling settingStore.set when there is no legacy node bookmark (#1191)

* Avoid calling settingStore.set when there is no legacy node bookmark

* nit
This commit is contained in:
Chenlei Hu
2024-10-09 16:02:14 -04:00
committed by GitHub
parent 1c5fd2465e
commit f6466d7062

View File

@@ -15,21 +15,24 @@ export const useNodeBookmarkStore = defineStore('nodeBookmark', () => {
const nodeDefStore = useNodeDefStore()
const migrateLegacyBookmarks = () => {
settingStore
.get('Comfy.NodeLibrary.Bookmarks')
.forEach((bookmark: string) => {
// If the bookmark is a folder, add it as a bookmark
if (bookmark.endsWith('/')) {
addBookmark(bookmark)
return
}
const category = bookmark.split('/').slice(0, -1).join('/')
const displayName = bookmark.split('/').pop()
const nodeDef = nodeDefStore.nodeDefsByDisplayName[displayName]
const legacyBookmarks = settingStore.get('Comfy.NodeLibrary.Bookmarks')
if (!legacyBookmarks.length) {
return
}
if (!nodeDef) return
addBookmark(`${category === '' ? '' : category + '/'}${nodeDef.name}`)
})
legacyBookmarks.forEach((bookmark: string) => {
// If the bookmark is a folder, add it as a bookmark
if (bookmark.endsWith('/')) {
addBookmark(bookmark)
return
}
const category = bookmark.split('/').slice(0, -1).join('/')
const displayName = bookmark.split('/').pop()
const nodeDef = nodeDefStore.nodeDefsByDisplayName[displayName]
if (!nodeDef) return
addBookmark(`${category === '' ? '' : category + '/'}${nodeDef.name}`)
})
settingStore.set('Comfy.NodeLibrary.Bookmarks', [])
}