Skip to content

Commit c90ed9e

Browse files
authored
feat: Cache database default connections (#11540)
Refs #10819
1 parent e4ee07d commit c90ed9e

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

frontend/src/store/interface/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface GlobalState {
4444
device: DeviceType;
4545
lastFilePath: string;
4646
currentDB: string;
47+
currentPgDB: string;
4748
currentRedisDB: string;
4849
showEntranceWarn: boolean;
4950
defaultNetwork: string;

frontend/src/store/modules/global.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const GlobalStore = defineStore({
3838
device: DeviceType.Desktop,
3939
lastFilePath: '',
4040
currentDB: '',
41+
currentPgDB: '',
4142
currentRedisDB: '',
4243
showEntranceWarn: true,
4344
defaultNetwork: 'all',
@@ -110,6 +111,9 @@ const GlobalStore = defineStore({
110111
setCurrentDB(name: string) {
111112
this.currentDB = name;
112113
},
114+
setCurrentPgDB(name: string) {
115+
this.currentPgDB = name;
116+
},
113117
setCurrentRedisDB(name: string) {
114118
this.currentRedisDB = name;
115119
},

frontend/src/views/database/mysql/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ const changeDatabase = async () => {
398398
for (const item of dbOptionsLocal.value) {
399399
if (item.database == currentDBName.value) {
400400
currentDB.value = item;
401+
globalStore.setCurrentDB(currentDB.value.database);
401402
appKey.value = item.type;
402403
appName.value = item.database;
403404
search();
@@ -409,6 +410,7 @@ const changeDatabase = async () => {
409410
if (item.database == currentDBName.value) {
410411
maskShow.value = false;
411412
currentDB.value = item;
413+
globalStore.setCurrentDB(currentDB.value.database);
412414
break;
413415
}
414416
}
@@ -532,7 +534,6 @@ const loadDBOptions = async () => {
532534
if (currentDB.value?.from === 'remote') {
533535
maskShow.value = false;
534536
}
535-
globalStore.setCurrentDB('');
536537
search();
537538
return;
538539
}

frontend/src/views/database/postgresql/index.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ const onChangeConn = async () => {
335335
336336
const goRemoteDB = async () => {
337337
if (currentDB.value) {
338-
globalStore.setCurrentDB(currentDB.value.database);
338+
globalStore.setCurrentPgDB(currentDB.value.database);
339339
}
340340
routerToName('PostgreSQL-Remote');
341341
};
@@ -348,7 +348,7 @@ const passwordRef = ref();
348348
349349
const onSetting = async () => {
350350
if (currentDB.value) {
351-
globalStore.setCurrentDB(currentDB.value.database);
351+
globalStore.setCurrentPgDB(currentDB.value.database);
352352
}
353353
routerToNameWithParams('PostgreSQL-Setting', { type: currentDB.value.type, database: currentDB.value.database });
354354
};
@@ -357,6 +357,7 @@ const changeDatabase = async () => {
357357
for (const item of dbOptionsLocal.value) {
358358
if (item.database == currentDBName.value) {
359359
currentDB.value = item;
360+
globalStore.setCurrentPgDB(currentDB.value.database);
360361
appKey.value = item.type;
361362
appName.value = item.database;
362363
search();
@@ -368,6 +369,7 @@ const changeDatabase = async () => {
368369
if (item.database == currentDBName.value) {
369370
maskShow.value = false;
370371
currentDB.value = item;
372+
globalStore.setCurrentPgDB(currentDB.value.database);
371373
break;
372374
}
373375
}
@@ -461,7 +463,7 @@ const loadDBOptions = async () => {
461463
let datas = res.data || [];
462464
dbOptionsLocal.value = [];
463465
dbOptionsRemote.value = [];
464-
currentDBName.value = globalStore.currentDB;
466+
currentDBName.value = globalStore.currentPgDB;
465467
for (const item of datas) {
466468
if (currentDBName.value && item.database === currentDBName.value) {
467469
currentDB.value = item;
@@ -480,7 +482,6 @@ const loadDBOptions = async () => {
480482
if (currentDB.value?.from === 'remote') {
481483
maskShow.value = false;
482484
}
483-
globalStore.setCurrentDB('');
484485
search();
485486
return;
486487
}

frontend/src/views/database/redis/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ const changeDatabase = async () => {
226226
for (const item of dbOptionsLocal.value) {
227227
if (item.database == currentDBName.value) {
228228
currentDB.value = item;
229+
globalStore.setCurrentRedisDB(currentDB.value.database);
229230
appKey.value = item.type;
230231
appName.value = item.database;
231232
appStatusRef.value?.onCheck(appKey.value, appName.value);
@@ -236,6 +237,7 @@ const changeDatabase = async () => {
236237
for (const item of dbOptionsRemote.value) {
237238
if (item.database == currentDBName.value) {
238239
currentDB.value = item;
240+
globalStore.setCurrentRedisDB(currentDB.value.database);
239241
break;
240242
}
241243
}
@@ -248,7 +250,7 @@ const loadDBOptions = async () => {
248250
let datas = res.data || [];
249251
dbOptionsLocal.value = [];
250252
dbOptionsRemote.value = [];
251-
currentDBName.value = globalStore.currentDB;
253+
currentDBName.value = globalStore.currentRedisDB;
252254
for (const item of datas) {
253255
if (currentDBName.value && item.database === currentDBName.value) {
254256
currentDB.value = item;

0 commit comments

Comments
 (0)