Repository navigation
feat(db_view): SQL 执行增加运行态指示,修复大查询期间界面无反馈 - #427
Merged
feigeCode merged 1 commit intoOct 20, 2026
Merged
Conversation
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #[423]
背景
用户反馈:查询数据量较大时,SQL 已经提交执行,但界面上没有任何指示,容易误以为执行没有成功。此前结果面板内其实已实现“执行中”加载态(Spinner、
正在解析并执行查询...、运行时间),但绝大多数大查询场景下它根本不会被渲染出来。根因
SqlEditorTab::render仅在has_results && results_visible时渲染结果面板;而每次执行开始都会先clear_results。因此执行期间has_results == false,面板连同内部的加载态一起消失。单条大 SELECT 要等结果全部返回才出现面板,期间界面零反馈。提取公共逻辑时发现:脚本执行路径有 100ms 计时任务,但 Auto 粘性会话 / 手动事务会话的执行路径只重置了开始时间,没有启动计时,
运行时间整段停在0.000s。首次连接、或手动事务新建会话时,从点击运行到 SQL 真正送出之间可能有数秒,这期间没有任何“执行中”指示。
面板进入运行态后工具栏显示停止键,但 Auto 建会话阶段尚未安装会话,
cancel_execution无法作废该次建立,查询仍会在会话就绪后照常执行。改动
crates/db_view/src/sql_editor_view.rsresult_panel_visible(has_results, is_visible, is_executing),语义:执行中无条件渲染面板;非执行态沿用“有结果且用户未隐藏”。
Render与render_sql_editor统一使用该判定,执行时即使无结果、用户此前关过面板,也会强制展开结果面板。QueryToolbarAction::Stop(运行中)时,在动作按钮旁显示Spinner + 运行中...(复用已有Query.runningi18n,无需新增文案)。这里刻意不读total_elapsed_ms,避免计时器每 100ms 触发包含 SQL 输入框的整个编辑器重绘;滚动耗时由结果面板内的“运行时间”展示。start_auto_session_and_run)与手动事务建会话(start_manual_transaction_and_run)在发起时调用container.begin_run_pending(cx),进入可见运行态。container.end_run_pending(pending_run, cx),保证指示器有始有终、不会卡在“运行中”:handle_stop_query:Auto 建会话阶段被取消时,显式自增auto_session_generation并复位auto_session_starting,作废该次建立,避免“停不掉的查询”。crates/db_view/src/sql_result_tab.rsenter_running_state(started_at, cx):清空结果后统一完成Executing { 0, 0 }状态、切回摘要页、面板置可见、重置并启动 100ms 计时任务。脚本执行与会话执行两条路径共用,会话执行因此也获得实时运行时间。
begin_run_pending(cx) -> u64:进入“已提交、SQL 尚未送出”的运行态,返回本次执行代次。该阶段不清空上一轮结果,真正开始执行时才清;会话建立失败时旧结果得以保留。end_run_pending(generation, cx):建会话失败/被打断时撤下运行态。仅当代次仍匹配且仍在执行时才收尾,避免误清已经开始的新查询。handle_run_query/handle_run_query_with_session改为复用enter_running_state,删除重复的计时器样板代码(净减约 90 行)。行为变化
测试
executing_query_keeps_the_result_panel_visible:覆盖面板可见性真值表(执行中无结果/有结果、面板隐藏、非执行态)。session_start_run_feedback_is_started_and_always_ended:断言 Auto/Manual 两条路径都启动运行指示,且 7 个中断分支都收尾(仅扫描生产代码,排除测试自身字符串)。cargo test -p db_view --lib:946 个测试,945 通过,0 失败,1 ignored。cargo check -p main --all-targets、cargo clippy -p db_view --all-targets均无告警。风险与说明
Checklist