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
@@ -570,7 +570,12 @@ export async function closeDatabaseConnection(connectionId: string, database: st
|
||||
return post("/api/connection/close-database", { connectionId, database });
|
||||
}
|
||||
|
||||
export async function saveConnections(configs: ConnectionConfig[]): Promise<void> {
|
||||
export async function saveConnections(configs: ConnectionConfig[], removedIds: string[] = []): Promise<void> {
|
||||
// Saving upserts; ids this client deleted are sent explicitly so that a
|
||||
// stale local list can never drop connections another client created.
|
||||
if (removedIds.length) {
|
||||
return post("/api/connection/save", { configs, removedIds });
|
||||
}
|
||||
return post("/api/connection/save", { configs });
|
||||
}
|
||||
|
||||
|
||||
@@ -2511,8 +2511,8 @@ export async function exportDocsHtml(filePath: string, snapshot: SchemaSnapshot,
|
||||
return invoke("docs_export_html", { filePath, snapshot, annotations, lang });
|
||||
}
|
||||
|
||||
export async function saveConnections(configs: ConnectionConfig[]): Promise<void> {
|
||||
return invoke("save_connections", { configs });
|
||||
export async function saveConnections(configs: ConnectionConfig[], removedIds: string[] = []): Promise<void> {
|
||||
return invoke("save_connections", { configs, removedIds });
|
||||
}
|
||||
|
||||
export async function loadConnections(): Promise<ConnectionConfig[]> {
|
||||
|
||||
@@ -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