From 293600d9b46d3819da710dd7008fbd869dc0ffe2 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 4 Jun 2026 13:54:20 +0800 Subject: [PATCH] fix: pass connection query timeout to execute_batch so ALTER respects configured timeout Previously execute_batch always used the hardcoded 30s default timeout, ignoring the user's query_timeout_secs connection setting. This caused long-running ALTER TABLE statements on large tables to time out even when the user configured a longer timeout or disabled it entirely. --- .../src/components/structure/TableStructureEditor.vue | 11 ++++++++++- apps/desktop/src/lib/tauri.ts | 3 ++- crates/dbx-core/src/query.rs | 3 ++- crates/dbx-web/src/routes/query.rs | 3 +++ src-tauri/src/commands/query.rs | 5 ++++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vue index f93943fa4f..415588eb28 100644 --- a/apps/desktop/src/components/structure/TableStructureEditor.vue +++ b/apps/desktop/src/components/structure/TableStructureEditor.vue @@ -41,6 +41,7 @@ import { useTheme } from "@/composables/useTheme"; import { useToast } from "@/composables/useToast"; import { type SqlHighlighter, createShikiSqlHighlighter } from "@/lib/sqlHighlighter"; import { copyToClipboard } from "@/lib/clipboard"; +import { queryTimeoutSecsForConnection } from "@/lib/queryTimeout"; import { type EditableStructureColumn, type EditableStructureIndex } from "@/lib/tableStructureEditorSql"; import { getTableStructureCapabilities } from "@/lib/tableStructureCapabilities"; import { @@ -676,7 +677,15 @@ async function applyChanges() { const sql = previewSqlText.value; const startedAt = Date.now(); try { - const result = await api.executeBatch(props.connectionId, props.database, pendingStatements.value); + const connection = store.getConfig(props.connectionId); + const timeoutSecs = queryTimeoutSecsForConnection(connection); + const result = await api.executeBatch( + props.connectionId, + props.database, + pendingStatements.value, + props.schema, + timeoutSecs, + ); await recordStructureHistory(sql, startedAt, true, result); toast(t("structureEditor.saved"), 2500); emit("saved", tableComment.value !== originalTableComment.value); diff --git a/apps/desktop/src/lib/tauri.ts b/apps/desktop/src/lib/tauri.ts index d7914b9214..2c93ee777a 100644 --- a/apps/desktop/src/lib/tauri.ts +++ b/apps/desktop/src/lib/tauri.ts @@ -520,8 +520,9 @@ export async function executeBatch( database: string, statements: string[], schema?: string, + timeoutSecs?: number, ): Promise { - return invoke("execute_batch", { connectionId, database, statements, schema }); + return invoke("execute_batch", { connectionId, database, statements, schema, timeoutSecs }); } export async function executeScript( diff --git a/crates/dbx-core/src/query.rs b/crates/dbx-core/src/query.rs index 01d7b45e28..e46091254a 100644 --- a/crates/dbx-core/src/query.rs +++ b/crates/dbx-core/src/query.rs @@ -1011,6 +1011,7 @@ pub async fn execute_statements( database: &str, statements: &[String], schema: Option<&str>, + timeout_secs: Option, ) -> Result { let pool_key = if database.is_empty() { connection_id.to_string() @@ -1031,7 +1032,7 @@ pub async fn execute_statements( sql, schema, None, - QueryExecutionOptions::default(), + QueryExecutionOptions { timeout_secs, ..Default::default() }, ) .await { diff --git a/crates/dbx-web/src/routes/query.rs b/crates/dbx-web/src/routes/query.rs index 8a94e73386..dc2ca0be55 100644 --- a/crates/dbx-web/src/routes/query.rs +++ b/crates/dbx-web/src/routes/query.rs @@ -53,6 +53,7 @@ pub struct ExecuteBatchRequest { pub database: String, pub statements: Vec, pub schema: Option, + pub timeout_secs: Option, } #[derive(Deserialize)] @@ -336,6 +337,7 @@ pub async fn execute_batch( &req.database, &req.statements, req.schema.as_deref(), + req.timeout_secs, ) .await .map_err(AppError)?; @@ -399,6 +401,7 @@ pub async fn execute_script( &req.database, &statements, req.schema.as_deref(), + None, ) .await .map_err(AppError)?; diff --git a/src-tauri/src/commands/query.rs b/src-tauri/src/commands/query.rs index be87a33c02..d91f35c44a 100644 --- a/src-tauri/src/commands/query.rs +++ b/src-tauri/src/commands/query.rs @@ -145,8 +145,10 @@ pub async fn execute_batch( database: String, statements: Vec, schema: Option, + timeout_secs: Option, ) -> Result { - dbx_core::query::execute_statements(&state, &connection_id, &database, &statements, schema.as_deref()).await + dbx_core::query::execute_statements(&state, &connection_id, &database, &statements, schema.as_deref(), timeout_secs) + .await } #[tauri::command] @@ -171,6 +173,7 @@ pub async fn execute_script( |db_type| dbx_core::sql::split_sql_statements_for_database(&sql, db_type), ), schema.as_deref(), + None, ) .await }