fix(connection): per-id saves stop cross-client connection clobber
This commit is contained in:
9 files changed
+188
-35
No files matched your search
@@ -157,7 +157,7 @@ describe("connectionStore pinned tree node removal", () => {
|
||||
|
||||
expect(store.connections).toEqual([connection]);
|
||||
expect(settingsStore.editorSettings.connectTimeoutInheritConnectionIds).toEqual([connection.id]);
|
||||
expect(saveConnections).toHaveBeenCalledWith([]);
|
||||
expect(saveConnections).toHaveBeenCalledWith([], ["connection-1"]);
|
||||
expect(saveConnections).toHaveBeenLastCalledWith([connection]);
|
||||
});
|
||||
|
||||
|
||||
@@ -9181,8 +9181,13 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function persistConnections(nextConnections: ConnectionConfig[] = connections.value) {
|
||||
await api.saveConnections(nextConnections.filter((connection) => connection.one_time !== true));
|
||||
async function persistConnections(nextConnections: ConnectionConfig[] = connections.value, removedIds: string[] = []) {
|
||||
const configs = nextConnections.filter((connection) => connection.one_time !== true);
|
||||
if (removedIds.length) {
|
||||
await api.saveConnections(configs, removedIds);
|
||||
return;
|
||||
}
|
||||
await api.saveConnections(configs);
|
||||
}
|
||||
|
||||
function sameIds(left: string[], right: string[]) {
|
||||
@@ -9231,6 +9236,10 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const nextConnectTimeoutIds = previousConnectTimeoutIds.filter((id) => nextConnections.some((connection) => connection.id === id));
|
||||
const nextQueryTimeoutIds = previousQueryTimeoutIds.filter((id) => nextConnections.some((connection) => connection.id === id));
|
||||
const connectionsChanged = nextConnections.length !== previousConnections.length || nextConnections.some((connection, index) => connection !== previousConnections[index]);
|
||||
// Deletion is explicit: the backend upserts whatever the save carries, so the
|
||||
// ids this client dropped from its list have to be named in the request.
|
||||
const nextConnectionIds = new Set(nextConnections.map((connection) => connection.id));
|
||||
const removedConnectionIds = previousConnections.filter((connection) => !nextConnectionIds.has(connection.id)).map((connection) => connection.id);
|
||||
const timeoutSettingsChanged = !sameIds(nextConnectTimeoutIds, previousConnectTimeoutIds) || !sameIds(nextQueryTimeoutIds, previousQueryTimeoutIds);
|
||||
const layoutChanged = nextLayout !== previousLayout;
|
||||
let connectionsPersisted = false;
|
||||
@@ -9239,7 +9248,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
|
||||
try {
|
||||
if (connectionsChanged) {
|
||||
await persistConnections(nextConnections);
|
||||
await persistConnections(nextConnections, removedConnectionIds);
|
||||
connectionsPersisted = true;
|
||||
}
|
||||
if (timeoutSettingsChanged) {
|
||||
|
||||
Reference in new issue
Block a user