Skip to content

Commit

Permalink
Remove migration logic (settings & templates storage location) (#1732)
Browse files Browse the repository at this point in the history
* Remove isNewUserSession handling

* Remove writing of setting and templates to localStorage
  • Loading branch information
huchenlei authored Nov 28, 2024
1 parent b008511 commit df3fff5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 55 deletions.
24 changes: 7 additions & 17 deletions src/extensions/core/nodeTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,19 @@ class ManageTemplates extends ComfyDialog {

async load() {
let templates = []
if (app.isNewUserSession) {
// New user so migrate existing templates
const json = localStorage.getItem(id)
if (json) {
templates = JSON.parse(json)
}
await api.storeUserData(file, json, { stringify: false })
} else {
const res = await api.getUserData(file)
if (res.status === 200) {
try {
templates = await res.json()
} catch (error) {}
} else if (res.status !== 404) {
console.error(res.status + ' ' + res.statusText)
}
const res = await api.getUserData(file)
if (res.status === 200) {
try {
templates = await res.json()
} catch (error) {}
} else if (res.status !== 404) {
console.error(res.status + ' ' + res.statusText)
}
return templates ?? []
}

async store() {
const templates = JSON.stringify(this.templates, undefined, 4)
localStorage.setItem(id, templates) // Backwards compatibility
try {
await api.storeUserData(file, templates, { stringify: false })
} catch (error) {
Expand Down
26 changes: 13 additions & 13 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export class ComfyApp {
lastExecutionError: { node_id: number } | null
progress: { value: number; max: number } | null
configuringGraph: boolean
isNewUserSession: boolean
ctx: CanvasRenderingContext2D
bodyTop: HTMLElement
bodyLeft: HTMLElement
Expand Down Expand Up @@ -186,6 +185,13 @@ export class ComfyApp {
return 'server'
}

/**
* @deprecated storage migration is no longer needed.
*/
get isNewUserSession() {
return false
}

constructor() {
this.vueAppReady = false
this.ui = new ComfyUI(this)
Expand Down Expand Up @@ -1707,11 +1713,8 @@ export class ComfyApp {

async #setUser() {
const userConfig = await api.getUserConfig()
if (typeof userConfig.migrated == 'boolean') {
// Single user mode migrated true/false for if the default user is created
if (!userConfig.migrated) {
this.isNewUserSession = true
}
// Return in single user mode.
if (userConfig.users === undefined) {
return
}

Expand All @@ -1725,18 +1728,15 @@ export class ComfyApp {
const { UserSelectionScreen } = await import('./ui/userSelection')

this.ui.menuContainer.style.display = 'none'
const { userId, username, created } =
await new UserSelectionScreen().show(users, user)
const { userId, username } = await new UserSelectionScreen().show(
users,
user
)
this.ui.menuContainer.style.display = ''

user = userId
localStorage['Comfy.userName'] = username
localStorage['Comfy.userId'] = user

if (created) {
api.user = user
this.isNewUserSession = true
}
}

api.user = user
Expand Down
18 changes: 1 addition & 17 deletions src/scripts/ui/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ export class ComfySettingsDialog extends ComfyDialog<HTMLDialogElement> {
) {
value = this.tryMigrateDeprecatedValue(id, value)

const json = JSON.stringify(value)
localStorage['Comfy.Settings.' + id] = json // backwards compatibility for extensions keep setting in storage

let oldValue = this.getSettingValue(id, undefined)
this.settingsValues[id] = value

Expand Down Expand Up @@ -142,20 +139,7 @@ export class ComfySettingsDialog extends ComfyDialog<HTMLDialogElement> {
throw new Error(`Setting ${id} of type ${type} must have a unique ID.`)
}

let value = this.getSettingValue(id)
if (value == null) {
if (this.app.isNewUserSession) {
// Check if we have a localStorage value but not a setting value and we are a new user
const localValue = localStorage['Comfy.Settings.' + id]
if (localValue) {
value = JSON.parse(localValue)
this.setSettingValue(id, value) // Store on the server
}
}
if (value == null) {
value = defaultValue
}
}
const value = this.getSettingValue(id) ?? defaultValue

// Trigger initial setting of value
onChange?.(value, undefined)
Expand Down
8 changes: 0 additions & 8 deletions tests-ui/tests/slow/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ describe('users', () => {
null,
{ stringify: false }
)
expect(s.app.isNewUserSession).toBeTruthy()
} else {
expect(s.app.isNewUserSession).toBeFalsy()
}

return { users, selection, ...s }
}

Expand Down Expand Up @@ -242,7 +238,6 @@ describe('users', () => {
null,
{ stringify: false }
)
expect(app.isNewUserSession).toBeTruthy()
})
it('doesnt show user creation if default user', async () => {
const { app } = await start({
Expand All @@ -255,7 +250,6 @@ describe('users', () => {
const { api } = await import('../../../src/scripts/api')
expect(api.storeSettings).toHaveBeenCalledTimes(0)
expect(api.storeUserData).toHaveBeenCalledTimes(0)
expect(app.isNewUserSession).toBeFalsy()
})
it('doesnt allow user switching', async () => {
const { app } = await start({
Expand All @@ -279,7 +273,6 @@ describe('users', () => {
const { api } = await import('../../../src/scripts/api')
expect(api.storeSettings).toHaveBeenCalledTimes(0)
expect(api.storeUserData).toHaveBeenCalledTimes(0)
expect(app.isNewUserSession).toBeFalsy()
})
it('doesnt show user creation if default user', async () => {
const { app } = await start({
Expand All @@ -292,7 +285,6 @@ describe('users', () => {
const { api } = await import('../../../src/scripts/api')
expect(api.storeSettings).toHaveBeenCalledTimes(0)
expect(api.storeUserData).toHaveBeenCalledTimes(0)
expect(app.isNewUserSession).toBeFalsy()
})
it('doesnt allow user switching', async () => {
const { app } = await start({
Expand Down

0 comments on commit df3fff5

Please sign in to comment.