Skip to content

fix: bypass idle check for all index creation and update task paths - #301

Closed
Johnson-zs wants to merge 1 commit into
linuxdeepin:develop/snipefrom
Johnson-zs:agent/bugfix/384711
Closed

Johnson-zs wants to merge 1 commit into
linuxdeepin:develop/snipefrom
Johnson-zs:agent/bugfix/384711

Conversation

@Johnson-zs

@Johnson-zs Johnson-zs commented Nov 27, 2026 •

Copy link
Copy Markdown

fix: bypass idle check for silent start create task when index DB missing

  1. Root cause: handleSilentStart() calls startTask(Create) with default
    forceBypass=false; Create auto-grades to Heavy, canRun() requires
    env.idle, so the task is queued and currentIndexStatus() returns
    "WaitingIdle" instead of executing
  2. Fix: pass forceBypass=true so the Create task bypasses the idle
    check and executes immediately when the index database is missing
  3. Impact: only affects silent start path when IndexDatabaseExists()
    returns false; manual update and other paths unchanged

fix: 修复静默启动时索引数据库不存在导致等待空闲的问题

  1. 根因:handleSilentStart() 调用 startTask(Create) 使用默认参数
    forceBypass=false,Create 任务自动分级为 Heavy,canRun() 要求
    用户空闲才放行,任务被入队导致 currentIndexStatus() 返回
    "WaitingIdle" 而非执行创建
  2. 方案:传入 forceBypass=true 使 Create 任务绕过空闲检查,
    在索引数据库不存在时立即执行创建
  3. 影响:仅影响静默启动路径中 IndexDatabaseExists() 返回 false
    的分支,手动更新及其他路径不受影响

Log: Fixed index showing "waiting for idle" instead of creating when database is missing
Influence:

  • Test silent start with no index database and user active
  • Verify index is created immediately without waiting for idle
  • Test normal update index flow still works as expected
    Log: 修复索引数据库不存在时静默启动显示"等待空闲"而非创建的问题
    Influence:
  • 测试无索引数据库且用户活跃时静默启动行为
  • 验证索引立即创建而不等待空闲
  • 测试正常更新索引流程无回归
    PMS: BUG-384711

Summary by Sourcery

Allow index creation tasks to bypass idle checks so missing databases are initialized immediately.

Bug Fixes:

  • Ensure index creation and related DBus-triggered index tasks start immediately without waiting for the user to become idle.
  • Fix silent-start behavior so missing index databases are created instead of remaining in a waiting-for-idle state.

@sourcery-ai

sourcery-ai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Uses of the API

Pass forceBypass=true for silent-start creation and D-Bus CreateIndexTask and UpdateIndexTask calls in both text and OCR services so these tasks bypass the idle check.

  • src/index/dbus/ocrindexdbus.cpp L129, L208, L214
  • src/index/dbus/textindexdbus.cpp L123, L209, L215

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Johnson-zs
Johnson-zs marked this pull request as draft November 27, 2026 12:17

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/index/dbus/textindexdbus.cpp" line_range="123" />
<code_context>
         if (!q->IndexDatabaseExists()) {
             qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
-            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
+            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);
             return;
         }
</code_context>
<issue_to_address>
**Full indexing ignores power safeguards**

When silent startup starts with a missing index database while the device is on battery or in power-save mode, or enters either state during the scan, `forceBypass` makes `TaskManager::canRun()` accept the Heavy Create and `onEnvStateChanged()` skip pausing it, so the full scan and optimization consume resources despite the power policy.

Change the forced-create path so it bypasses only the idle gate and still honors battery and power-save checks and pauses.
</issue_to_address>

### Comment 2
<location path="src/index/dbus/textindexdbus.cpp" line_range="123" />
<code_context>
         if (!q->IndexDatabaseExists()) {
             qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
-            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
+            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);
             return;
         }
</code_context>
<issue_to_address>
**Unavailable paths leave index uncreated**

When a configured indexed directory is temporarily unavailable when silent startup launches the forced Create, such as while a mount is still coming online, `CreateIndexHandler` returns failure when an indexed directory is unavailable, and the silent-start `call_once` has already consumed its only attempt. Later file-list events are skipped while the database is not ready, so the index remains absent after the directory becomes available.

Defer or retry the Create when its source directories become available instead of consuming the one-time startup attempt on a missing path.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

if (!q->IndexDatabaseExists()) {
qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Full indexing ignores power safeguards

When silent startup starts with a missing index database while the device is on battery or in power-save mode, or enters either state during the scan, forceBypass makes TaskManager::canRun() accept the Heavy Create and onEnvStateChanged() skip pausing it, so the full scan and optimization consume resources despite the power policy.

Change the forced-create path so it bypasses only the idle gate and still honors battery and power-save checks and pauses.

Prompt for AI agents
In `src/index/dbus/textindexdbus.cpp` at line 123:

**Full indexing ignores power safeguards**

When silent startup starts with a missing index database while the device is on battery or in power-save mode, or enters either state during the scan, `forceBypass` makes `TaskManager::canRun()` accept the Heavy Create and `onEnvStateChanged()` skip pausing it, so the full scan and optimization consume resources despite the power policy.

Change the forced-create path so it bypasses only the idle gate and still honors battery and power-save checks and pauses.

if (!q->IndexDatabaseExists()) {
qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Unavailable paths leave index uncreated

When a configured indexed directory is temporarily unavailable when silent startup launches the forced Create, such as while a mount is still coming online, CreateIndexHandler returns failure when an indexed directory is unavailable, and the silent-start call_once has already consumed its only attempt. Later file-list events are skipped while the database is not ready, so the index remains absent after the directory becomes available.

Defer or retry the Create when its source directories become available instead of consuming the one-time startup attempt on a missing path.

Prompt for AI agents
In `src/index/dbus/textindexdbus.cpp` at line 123:

**Unavailable paths leave index uncreated**

When a configured indexed directory is temporarily unavailable when silent startup launches the forced Create, such as while a mount is still coming online, `CreateIndexHandler` returns failure when an indexed directory is unavailable, and the silent-start `call_once` has already consumed its only attempt. Later file-list events are skipped while the database is not ready, so the index remains absent after the directory becomes available.

Defer or retry the Create when its source directories become available instead of consuming the one-time startup attempt on a missing path.

1. Root cause: handleSilentStart(), CreateIndexTask(), and
   UpdateIndexTask() in both TextIndexDBus and OcrIndexDBus call
   startTask() with default forceBypass=false; Create auto-grades to
   Heavy, canRun() requires env.idle, so the task is queued and
   currentIndexStatus() returns "WaitingIdle" instead of executing.
   On new machines the daemon triggers CreateIndexTask within seconds
   via D-Bus, long before the 180s handleSilentStart timer fires.
2. Fix: pass forceBypass=true in all three paths: handleSilentStart
   (existing), CreateIndexTask, and UpdateIndexTask, so index
   creation and update bypass the idle check and execute immediately.
   Consistent with ForceUpdateIndex which already passes
   forceBypass=true.
3. Impact: affects index creation and update when invoked via D-Bus
   by the daemon or silent start, for both text and OCR index
   services. ForceUpdateIndex path unchanged (already had
   forceBypass=true). Manual update via UI already worked correctly.

fix: 修复所有索引创建和更新任务路径的空闲检查阻塞问题

1. 根因:TextIndexDBus 和 OcrIndexDBus 的 handleSilentStart()、
   CreateIndexTask()、UpdateIndexTask() 调用 startTask() 使用默认参数
   forceBypass=false,Create 任务自动分级为 Heavy,canRun() 要求用户
   空闲才放行,任务被入队导致 currentIndexStatus() 返回"WaitingIdle"
   而非执行。新装机器上 daemon 通过 D-Bus 在数秒内触发
   CreateIndexTask,远早于 handleSilentStart 的 180 秒定时器。
2. 方案:在三条路径中均传入 forceBypass=true:handleSilentStart
   (已有)、CreateIndexTask、UpdateIndexTask,使索引创建和更新绕过
   空闲检查立即执行,与已传 forceBypass=true 的 ForceUpdateIndex 保持
   一致。
3. 影响:影响 daemon 通过 D-Bus 调用或静默启动触发的索引创建和更新
   路径,覆盖文本索引和 OCR 索引服务。ForceUpdateIndex 路径不变(已有
   forceBypass=true),UI 手动更新功能无变化。

Log: Fixed index showing "waiting for idle" instead of creating on new machines
Influence:
  - Test index creation on a fresh machine with no index database and user active
  - Test CreateIndexTask D-Bus call bypasses idle check for both text and OCR
  - Test UpdateIndexTask D-Bus call bypasses idle check for both text and OCR
  - Test handleSilentStart still creates index when database is missing
  - Verify normal index update flow via UI still works as expected
Log: 修复新装机器上索引显示"等待空闲"而非创建的问题
Influence:
  - 测试新装机器无索引数据库且用户活跃时索引创建行为
  - 测试 CreateIndexTask D-Bus 调用绕过空闲检查(文本和 OCR)
  - 测试 UpdateIndexTask D-Bus 调用绕过空闲检查(文本和 OCR)
  - 测试 handleSilentStart 在数据库不存在时仍创建索引
  - 验证通过 UI 正常更新索引流程无回归
PMS: BUG-384711
@Johnson-zs Johnson-zs changed the title fix: bypass idle check for silent start create task when index DB missing fix: bypass idle check for all index creation and update task paths Nov 30, 2026
@Johnson-zs
Johnson-zs marked this pull request as ready for review November 30, 2026 05:03
@Johnson-zs Johnson-zs closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants