Skip to content

Conversation

@Soulter
Copy link
Member

@Soulter Soulter commented Sep 21, 2025

fixes: #2782


Motivation / 动机

修复 278

Modifications / 改动点

修改了 sqlite.py,导致 2782 问题的原因和 89d3fd5 类似。

Verification Steps / 验证步骤

参考 2782

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

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 摘要

修复对话管理中损坏的关键词搜索,方法是扩展 SQL 过滤器以覆盖内容并处理 Unicode;并在会话管理和对话页面上应用广泛的 UI 样式改进,以简化布局、更新表单控件变体并提高密度和一致性。

Bug 修复:

  • 恢复对话管理中的关键词搜索,方法是同时匹配标题和内容,并在 SQL 查询中转义 Unicode。

功能增强:

  • 在后端查询中添加按消息类型和平台过滤对话的支持
  • 重构会话管理页面,采用扁平卡片、单填充输入框、紧凑数据表和仅图标控件
  • 重构对话页面,采用组合式标题、用于过滤器的组合框和单填充输入框、紧凑表格样式和仅图标操作按钮
  • 移除多余的 CSS 规则并收紧组件间距,以实现一致的 UI
Original summary in English

Summary by Sourcery

Fix broken keyword search in conversation management by extending the SQL filter to cover content and handle unicode, and apply wide UI style refinements across the Session Management and Conversation pages to simplify layouts, update form control variants, and improve density and consistency.

Bug Fixes:

  • Restore keyword search in conversation management by matching both title and content and escaping unicode in the SQL query

Enhancements:

  • Add support for filtering conversations by message type and platform in the backend query
  • Refactor Session Management page with flat cards, solo-filled inputs, compact data table, and icon-only controls
  • Refactor Conversation page with combined header, combobox and solo-filled inputs for filters, compact table styling, and icon-only action buttons
  • Remove redundant CSS rules and tighten component spacing for consistent UI

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.

大家好 - 我已经审阅了你的更改 - 这里有一些反馈:

  • 在合并之前,请从 sqlite.py 中删除调试打印语句 (print(count_query)print(result_query))。
  • 此 PR 将搜索修复逻辑与广泛的 UI 变体/样式重构混合在一起——考虑将 UI 更改拆分到单独的 PR 中,以便可以单独审查关键字搜索修复。
  • 仔细检查 get_filtered_conversations 中的 message_types 过滤器,因为它目前使用 ConversationV2.user_id.ilike,这可能无法正确地定位消息类型数据。
供 AI 代理参考的提示
请处理此代码审查中的注释:

## 总体评论
- 在合并之前,请从 sqlite.py 中删除调试打印语句 (`print(count_query)``print(result_query)`)。
- 此 PR 将搜索修复逻辑与广泛的 UI 变体/样式重构混合在一起——考虑将 UI 更改拆分到单独的 PR 中,以便可以单独审查关键字搜索修复。
- 仔细检查 `get_filtered_conversations` 中的 `message_types` 过滤器,因为它目前使用 `ConversationV2.user_id.ilike`,这可能无法正确地定位消息类型数据。

## 单独评论

### 评论 1
<location> `dashboard/src/views/SessionManagementPage.vue:806-808` </location>
<code_context>
-}

-.v-data-table >>> .v-data-table__td {
+.v-data-table>>>.v-data-table__td {
   padding: 8px 16px !important;
   vertical-align: middle !important;
 }

</code_context>

<issue_to_address>
**issue (bug_risk):** 深度选择器从 '>>>' 更改为 '>>>',这可能是一个拼写错误。

'>>>' 不是标准的 CSS 组合器。如果你想使用 Vue 深度选择器,请使用 '::v-deep' 或 '/deep/'。请确认这在你的构建设置中有效。
</issue_to_address>

### 评论 2
<location> `astrbot/core/db/sqlite.py:164-158` </location>
<code_context>
+                        ConversationV2.content.ilike(f"%{search_query}%")
+                    )
+                )
+            if "message_types" in kwargs and len(kwargs["message_types"]) > 0:
+                for msg_type in kwargs["message_types"]:
+                    base_query = base_query.where(
+                        ConversationV2.user_id.ilike(f"%:{msg_type}:%")
+                    )
</code_context>

<issue_to_address>
**issue:** 消息类型过滤使用 user_id ilike 和消息类型子字符串。

使用 user_id 上的 ilike 进行消息类型过滤不可靠,可能会产生不正确的匹配。最好在有专用 message_type 字段时通过该字段进行过滤。
</issue_to_address>

### 评论 3
<location> `astrbot/core/db/sqlite.py:176-177` </location>
<code_context>

             # Get total count matching the filters
             count_query = select(func.count()).select_from(base_query.subquery())
+            print(count_query)
             total_count = await session.execute(count_query)
             total = total_count.scalar_one()

</code_context>

<issue_to_address>
**issue:** 调试打印语句留在生产代码中。

请在合并之前删除打印语句或使用适当的日志记录。
</issue_to_address>

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

Hey there - I've reviewed your changes - here's some feedback:

  • Please remove the debugging print statements (print(count_query) and print(result_query)) from sqlite.py before merging.
  • This PR mixes the search-fix logic with extensive UI variant/style refactors—consider splitting the UI changes into a separate PR so the keyword search fix can be reviewed in isolation.
  • Double-check the message_types filter in get_filtered_conversations, as it currently uses ConversationV2.user_id.ilike which may not correctly target message type data.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Please remove the debugging print statements (`print(count_query)` and `print(result_query)`) from sqlite.py before merging.
- This PR mixes the search-fix logic with extensive UI variant/style refactors—consider splitting the UI changes into a separate PR so the keyword search fix can be reviewed in isolation.
- Double-check the `message_types` filter in get_filtered_conversations, as it currently uses `ConversationV2.user_id.ilike` which may not correctly target message type data.

## Individual Comments

### Comment 1
<location> `dashboard/src/views/SessionManagementPage.vue:806-808` </location>
<code_context>
-}

-.v-data-table >>> .v-data-table__td {
+.v-data-table>>>.v-data-table__td {
   padding: 8px 16px !important;
   vertical-align: middle !important;
 }

</code_context>

<issue_to_address>
**issue (bug_risk):** Deep selector changed from '>>>' to '>>>', which may be a typo.

'>>>' is not a standard CSS combinator. If you meant to use a Vue deep selector, use '::v-deep' or '/deep/' instead. Please confirm this works in your build setup.
</issue_to_address>

### Comment 2
<location> `astrbot/core/db/sqlite.py:164-158` </location>
<code_context>
+                        ConversationV2.content.ilike(f"%{search_query}%")
+                    )
+                )
+            if "message_types" in kwargs and len(kwargs["message_types"]) > 0:
+                for msg_type in kwargs["message_types"]:
+                    base_query = base_query.where(
+                        ConversationV2.user_id.ilike(f"%:{msg_type}:%")
+                    )
</code_context>

<issue_to_address>
**issue:** Message type filtering uses user_id ilike with message type substring.

Using ilike on user_id for message type filtering is unreliable and may produce incorrect matches. It's better to filter by a dedicated message_type field if available.
</issue_to_address>

### Comment 3
<location> `astrbot/core/db/sqlite.py:176-177` </location>
<code_context>

             # Get total count matching the filters
             count_query = select(func.count()).select_from(base_query.subquery())
+            print(count_query)
             total_count = await session.execute(count_query)
             total = total_count.scalar_one()

</code_context>

<issue_to_address>
**issue:** Debug print statements left in production code.

Please remove the print statement or use appropriate logging before merging.
</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 9f939b4 into master Sep 21, 2025
5 checks passed
@Soulter Soulter deleted the fix/2782 branch September 21, 2025 12:55
@Soulter Soulter mentioned this pull request Sep 21, 2025
2 tasks
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.

[Bug] 对话管理页面的关键词搜索功能失效,无法通过ID搜索到对话

2 participants