feat: Cache database default connections (#11540)

Refs  #10819
This commit is contained in:
ssongliu
2026-01-04 06:39:40 +00:00
committed by GitHub
parent e4ee07d36b
commit c90ed9e873
5 changed files with 15 additions and 6 deletions
+1
View File
@@ -44,6 +44,7 @@ export interface GlobalState {
device: DeviceType;
lastFilePath: string;
currentDB: string;
currentPgDB: string;
currentRedisDB: string;
showEntranceWarn: boolean;
defaultNetwork: string;
+4
View File
@@ -38,6 +38,7 @@ const GlobalStore = defineStore({
device: DeviceType.Desktop,
lastFilePath: '',
currentDB: '',
currentPgDB: '',
currentRedisDB: '',
showEntranceWarn: true,
defaultNetwork: 'all',
@@ -110,6 +111,9 @@ const GlobalStore = defineStore({
setCurrentDB(name: string) {
this.currentDB = name;
},
setCurrentPgDB(name: string) {
this.currentPgDB = name;
},
setCurrentRedisDB(name: string) {
this.currentRedisDB = name;
},
+2 -1
View File
@@ -398,6 +398,7 @@ const changeDatabase = async () => {
for (const item of dbOptionsLocal.value) {
if (item.database == currentDBName.value) {
currentDB.value = item;
globalStore.setCurrentDB(currentDB.value.database);
appKey.value = item.type;
appName.value = item.database;
search();
@@ -409,6 +410,7 @@ const changeDatabase = async () => {
if (item.database == currentDBName.value) {
maskShow.value = false;
currentDB.value = item;
globalStore.setCurrentDB(currentDB.value.database);
break;
}
}
@@ -532,7 +534,6 @@ const loadDBOptions = async () => {
if (currentDB.value?.from === 'remote') {
maskShow.value = false;
}
globalStore.setCurrentDB('');
search();
return;
}
@@ -335,7 +335,7 @@ const onChangeConn = async () => {
const goRemoteDB = async () => {
if (currentDB.value) {
globalStore.setCurrentDB(currentDB.value.database);
globalStore.setCurrentPgDB(currentDB.value.database);
}
routerToName('PostgreSQL-Remote');
};
@@ -348,7 +348,7 @@ const passwordRef = ref();
const onSetting = async () => {
if (currentDB.value) {
globalStore.setCurrentDB(currentDB.value.database);
globalStore.setCurrentPgDB(currentDB.value.database);
}
routerToNameWithParams('PostgreSQL-Setting', { type: currentDB.value.type, database: currentDB.value.database });
};
@@ -357,6 +357,7 @@ const changeDatabase = async () => {
for (const item of dbOptionsLocal.value) {
if (item.database == currentDBName.value) {
currentDB.value = item;
globalStore.setCurrentPgDB(currentDB.value.database);
appKey.value = item.type;
appName.value = item.database;
search();
@@ -368,6 +369,7 @@ const changeDatabase = async () => {
if (item.database == currentDBName.value) {
maskShow.value = false;
currentDB.value = item;
globalStore.setCurrentPgDB(currentDB.value.database);
break;
}
}
@@ -461,7 +463,7 @@ const loadDBOptions = async () => {
let datas = res.data || [];
dbOptionsLocal.value = [];
dbOptionsRemote.value = [];
currentDBName.value = globalStore.currentDB;
currentDBName.value = globalStore.currentPgDB;
for (const item of datas) {
if (currentDBName.value && item.database === currentDBName.value) {
currentDB.value = item;
@@ -480,7 +482,6 @@ const loadDBOptions = async () => {
if (currentDB.value?.from === 'remote') {
maskShow.value = false;
}
globalStore.setCurrentDB('');
search();
return;
}
+3 -1
View File
@@ -226,6 +226,7 @@ const changeDatabase = async () => {
for (const item of dbOptionsLocal.value) {
if (item.database == currentDBName.value) {
currentDB.value = item;
globalStore.setCurrentRedisDB(currentDB.value.database);
appKey.value = item.type;
appName.value = item.database;
appStatusRef.value?.onCheck(appKey.value, appName.value);
@@ -236,6 +237,7 @@ const changeDatabase = async () => {
for (const item of dbOptionsRemote.value) {
if (item.database == currentDBName.value) {
currentDB.value = item;
globalStore.setCurrentRedisDB(currentDB.value.database);
break;
}
}
@@ -248,7 +250,7 @@ const loadDBOptions = async () => {
let datas = res.data || [];
dbOptionsLocal.value = [];
dbOptionsRemote.value = [];
currentDBName.value = globalStore.currentDB;
currentDBName.value = globalStore.currentRedisDB;
for (const item of datas) {
if (currentDBName.value && item.database === currentDBName.value) {
currentDB.value = item;