From 74a6b9b0e17ba69d5cd9a73f690691e94d6d4d8e Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Sun, 18 Feb 2024 14:32:13 +0800 Subject: [PATCH] perf: optimize conflict connection name when duplicating --- frontend/src/stores/dialog.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/frontend/src/stores/dialog.js b/frontend/src/stores/dialog.js index b619c74..b0e36d7 100644 --- a/frontend/src/stores/dialog.js +++ b/frontend/src/stores/dialog.js @@ -124,13 +124,29 @@ const useDialogStore = defineStore('dialog', { async openDuplicateDialog(name) { const connStore = useConnectionStore() - const profile = await connStore.getConnectionProfile(name) - if (profile != null) { - profile.name += '2' - this.connParam = profile - } else { - this.connParam = connStore.newDefaultConnection(name) - } + this.connParam = {} + let profile + let suffix = 1 + do { + let profileName = name + if (suffix > 1) { + profileName += suffix + } + profile = await connStore.getConnectionProfile(profileName) + if (profile != null) { + suffix += 1 + if (profileName === name) { + this.connParam = profile + } + } else { + this.connParam = connStore.mergeConnectionProfile( + connStore.newDefaultConnection(profileName), + this.connParam, + ) + this.connParam.name = profileName + break + } + } while (true) this.connType = ConnDialogType.NEW this.connDialogVisible = true },