fix: 素材列表默认按created_at倒序,新上传素材在最前面 #505

Merged
auto-approve-bot merged 3 commits from fix/asset-list-order-by into develop 2026-07-18 15:05:08 +08:00
Owner

问题:素材列表三个查询接口(find_by_library / find_by_project / find_by_library_and_file_type)全部缺少 ORDER BY 子句,PostgreSQL 按物理存储顺序返回数据。素材多过一页时,新上传的素材可能被排到后面,用户看不到。

修复:三个接口统一加 ORDER BY created_at DESC,最新上传的在最前面。

测试:新增3个单元测试验证排序正确性,全部通过。

关联:#406

**问题**:素材列表三个查询接口(find_by_library / find_by_project / find_by_library_and_file_type)全部缺少 ORDER BY 子句,PostgreSQL 按物理存储顺序返回数据。素材多过一页时,新上传的素材可能被排到后面,用户看不到。 **修复**:三个接口统一加 `ORDER BY created_at DESC`,最新上传的在最前面。 **测试**:新增3个单元测试验证排序正确性,全部通过。 **关联**:#406
xiaoxia added the bugbackend labels 2026-07-18 13:57:24 +08:00
xiaoxia added 1 commit 2026-07-18 13:57:24 +08:00
fix: 素材列表默认按created_at倒序排列,新上传的在最前面
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 16s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 20s
AI Code Review / AI Code Review (pull_request) Failing after 33s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 57s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 38s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 21s
Auto Merge CI PRs / Auto Merge on CI Green + Approved (pull_request) Successful in 1m13s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 1m14s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m35s
29d0ee5ba1
三个列表查询接口全部缺少ORDER BY子句,PostgreSQL按物理存储顺序返回,
导致新上传的素材可能不出现在第一页。

修复:
- find_by_library: 加 ORDER BY created_at DESC
- find_by_project: 加 ORDER BY created_at DESC
- find_by_library_and_file_type: 加 ORDER BY created_at DESC

新增3个单元测试验证排序正确性。
xiaoxia added 1 commit 2026-07-18 14:40:17 +08:00
style: black格式化测试文件
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 17s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 30s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 53s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 58s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 46s
Auto Merge CI PRs / Auto Merge on CI Green + Approved (pull_request) Successful in 1m15s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 1m16s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m50s
AI Code Review / AI Code Review (pull_request) Successful in 4m55s
2a7565ea7e

🚀 预览环境已部署

项目 详情
PR号 #505
预览链接 https://pr-505.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #505 | | 预览链接 | [https://pr-505.preview.xiaoxiajianji.com](https://pr-505.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
Collaborator

代码审查结果 - PR #505

⚠️ 问题(0个需要修改)

💡 建议(1个可选)

  1. packages/adapters/sqlalchemy_impl/asset_repository.py 第23, 37, 56行:建议确认 AssetModel.created_at 字段在数据库层面已建立索引。
    • 原因:在数据量较大的情况下,对非索引字段进行排序(ORDER BY)会导致数据库出现 Using filesort(MySQL)或类似的排序操作,消耗大量内存和CPU,严重降低查询性能。
    • 建议:检查对应的 Migration 文件或 Model 定义,确保 created_at 字段上有索引(例如 Index('idx_created_at', 'created_at'))。

格式检查通过 | 逻辑审查通过 | ⚠️ 建议关注性能


🤖 由 AI 代码审查机器人自动生成 | 2026-07-18 14:45:13 | 模型:

## 代码审查结果 - PR #505 ### ⚠️ 问题(0个需要修改) 无 ### 💡 建议(1个可选) 1. **packages/adapters/sqlalchemy_impl/asset_repository.py 第23, 37, 56行**:建议确认 `AssetModel.created_at` 字段在数据库层面已建立索引。 - **原因**:在数据量较大的情况下,对非索引字段进行排序(`ORDER BY`)会导致数据库出现 `Using filesort`(MySQL)或类似的排序操作,消耗大量内存和CPU,严重降低查询性能。 - **建议**:检查对应的 Migration 文件或 Model 定义,确保 `created_at` 字段上有索引(例如 `Index('idx_created_at', 'created_at')`)。 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ⚠️ 建议关注性能 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-18 14:45:13 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia added 1 commit 2026-07-18 15:00:39 +08:00
style: isort修复import排序
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Deploy Production (pull_request) Has been skipped
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 15s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 17s
AI Code Review / AI Code Review (pull_request) Failing after 30s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 22s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 50s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 2m12s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 2m32s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m34s
Auto Merge CI PRs / Auto Merge on CI Green + Approved (pull_request) Successful in 4m28s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 29s
d4c7dcbd11
auto-approve-bot approved these changes 2026-07-18 15:03:12 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-07-18 15:03:12 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot merged commit e724225f8a into develop 2026-07-18 15:05:08 +08:00
auto-approve-bot deleted branch fix/asset-list-order-by 2026-07-18 15:05:08 +08:00

🗑️ 预览环境已清理

PR #505 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #505 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.