Skip to content

Conversation

@ctrlkk
Copy link
Contributor

@ctrlkk ctrlkk commented Oct 6, 2025

这是对 #2952 的重新提交,是一个更干净的提交,不包含多余的commits。


Motivation / 动机

Modifications / 改动点

1、优化了sqlite配置,启用WAL模式和NORMAL,优化并发读写性能,同时增加了一些缓存策略。
2、对话数据,列表显示会话id字段,查询增加会话id条件(会话id指cid,原来的sessionId改为用户id)。
3、对话数据,增加请求打断功能,现在查询时仍然允许输入,如上一次请求没有完成将会被取消。
4、会话管理,搜索框增加输入防抖。

Verification Steps / 验证步骤

Screenshots or Test Results / 运行截图或测试结果

新的sqlite配置中普通查询平均快100ms左右
图片

这是原来的配置
图片

写入性能还未测试

PixPin_2025-10-04_22-21-51

Compatibility & Breaking Changes / 兼容性与破坏性变更

  • 这是一个破坏性变更 (Breaking Change)。/ This is a breaking change.
  • 这不是一个破坏性变更。/ This is NOT a breaking change.

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Sourcery 总结

优化 SQLite 性能,并提升对话和会话管理页面的交互性和性能。

新功能:

  • 允许通过中止之前的请求来中断正在进行的对话列表查询
  • 为会话搜索输入框添加防抖功能,以减少冗余请求

改进:

  • 启用 SQLite WAL 模式并应用调整后的 PRAGMA 设置 (synchronous, cache_size, temp_store, mmap_size, optimize),以提高并发读/写性能
  • 在对话搜索条件中包含 conversation_id,以支持按对话 ID 过滤
  • 在 ConversationPage 表中显示对话 ID 列,并将 sessionId 列重命名为用户 ID
  • 允许筛选输入项 (platform, type, search) 在加载期间保持可交互状态
  • 将自定义防抖实现替换为 lodash debounce,并为长 ID 添加 text-truncate 样式
Original summary in English

Summary by Sourcery

Optimize SQLite performance and enhance interactivity and performance on the conversation and session management pages.

New Features:

  • Allow interrupting in-flight conversation list queries by aborting previous requests
  • Add debounce to session search input to reduce redundant requests

Enhancements:

  • Enable SQLite WAL mode and apply tuned PRAGMA settings (synchronous, cache_size, temp_store, mmap_size, optimize) to improve concurrent read/write performance
  • Include conversation_id in conversation search criteria to support filtering by conversation ID
  • Display conversation ID column and rename sessionId column to user ID in ConversationPage table
  • Allow filter inputs (platform, type, search) to remain interactive during loading
  • Replace custom debounce implementation with lodash debounce and add text-truncate styling for long IDs

Sourcery 总结

优化 SQLite 数据库初始化以提高性能;通过可取消的查询、防抖输入以及丰富的搜索和显示功能来增强会话和对话管理。

新功能:

  • 中止正在进行的对话列表请求,以取消过时的查询。
  • 为对话筛选器和会话搜索输入添加防抖处理,以减少冗余的 API 调用。

改进:

  • 将 SQLite 配置为 WAL 模式并调整 PRAGMA 设置,以获得更好的并发读写性能。
  • 扩展对话搜索和显示:包括 conversation_id 过滤,添加对话 ID 列,并在加载期间保持筛选器控件的交互性。
  • 更新对话表布局,将 sessionId 重命名为 user ID,并对长 ID 应用 text-truncate 样式。
Original summary in English

Summary by Sourcery

Optimize SQLite database initialization for improved performance; enhance conversation and session management with cancelable queries, debounced inputs, and enriched search and display capabilities.

New Features:

  • Abort in-progress conversation list requests to cancel outdated queries.
  • Add debounced handling for conversation filters and session search inputs to reduce redundant API calls.

Enhancements:

  • Configure SQLite with WAL mode and tuned PRAGMA settings for better concurrent read/write performance.
  • Extend conversation search and display: include conversation_id filtering, add a conversation ID column, and keep filter controls interactive during loading.
  • Update conversation table layout by renaming sessionId to user ID and applying text-truncate styling for long IDs.

@auto-assign auto-assign bot requested review from advent259141 and anka-afk October 6, 2025 03:26
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

你好 - 我已审阅了你的更改,它们看起来很棒!

AI 代理的提示
请解决此代码审查中的评论:

## 单独评论

### 评论 1
<location> `astrbot/core/db/sqlite.py:169` </location>
<code_context>
                         col(ConversationV2.title).ilike(f"%{search_query}%"),
                         col(ConversationV2.content).ilike(f"%{search_query}%"),
                         col(ConversationV2.user_id).ilike(f"%{search_query}%"),
+                        col(ConversationV2.conversation_id).ilike(f"%{search_query}%"),
                     )
                 )
</code_context>

<issue_to_address>
**建议 (性能):** 将 conversation_id 添加到搜索中可能会影响查询性能。

如果 conversation_id 未建立索引,搜索可能会变慢,尤其是在大型表中。考虑为此列建立索引或跟踪查询性能。

建议的实现:

```python
            await conn.execute(text("PRAGMA cache_size=50000"))
            await conn.execute(text("PRAGMA temp_store=MEMORY"))
            await conn.execute(text("PRAGMA mmap_size=268435456"))
            await conn.execute(text("PRAGMA optimize"))
            # Ensure index on conversation_id for performance
            await conn.execute(text("CREATE INDEX IF NOT EXISTS idx_conversation_id ON ConversationV2(conversation_id)"))
            await conn.commit()

```

如果你有专门的数据库迁移系统,你应该在那里添加索引创建,而不是直接在连接设置中。另外,请确保表名和列名与你的 schema 匹配(在 SQLite 中,大小写敏感性可能很重要)。
</issue_to_address>

Sourcery 对开源免费 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我更有用!请在每条评论上点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey there - I've reviewed your changes and they look great!

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

## Individual Comments

### Comment 1
<location> `astrbot/core/db/sqlite.py:169` </location>
<code_context>
                         col(ConversationV2.title).ilike(f"%{search_query}%"),
                         col(ConversationV2.content).ilike(f"%{search_query}%"),
                         col(ConversationV2.user_id).ilike(f"%{search_query}%"),
+                        col(ConversationV2.conversation_id).ilike(f"%{search_query}%"),
                     )
                 )
</code_context>

<issue_to_address>
**suggestion (performance):** Adding conversation_id to search may impact query performance.

If conversation_id is not indexed, searches may become slower, especially on large tables. Consider indexing this column or tracking query performance.

Suggested implementation:

```python
            await conn.execute(text("PRAGMA cache_size=50000"))
            await conn.execute(text("PRAGMA temp_store=MEMORY"))
            await conn.execute(text("PRAGMA mmap_size=268435456"))
            await conn.execute(text("PRAGMA optimize"))
            # Ensure index on conversation_id for performance
            await conn.execute(text("CREATE INDEX IF NOT EXISTS idx_conversation_id ON ConversationV2(conversation_id)"))
            await conn.commit()

```

If you have a dedicated database migration system, you should add the index creation there instead of directly in the connection setup. Also, ensure that the table name and column name match your schema (case sensitivity may matter in SQLite).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Soulter Soulter merged commit dcd8a10 into AstrBotDevs:master Oct 6, 2025
5 checks passed
@ctrlkk ctrlkk deleted the new branch October 9, 2025 03:55
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