feat: #1776 素材库 asset_count 自动同步维护 #1787
Reference in New Issue
Block a user
Delete Branch "feature/asset-count-sync-1776"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Issue #1776: 素材上传后 asset_libraries.asset_count 同步维护
改动概要
核心方案:在 asset_repository 层自动维护计数,同一事务内原子更新
asset_repository.create()→ 自动asset_count + 1,total_size + file_sizeasset_repository.delete()→ 硬删除时自动asset_count - 1(已 deleted 的不重复扣减)asset_repository.batch_delete()→ 软删除时按库分组批量扣减,只减非 deleted 的CASE WHEN兼容 SQLite(测试)和 PostgreSQL(生产)接口层改动:
increment_asset_count/decrement_asset_count从 async 改为 sync(修复 bug:实际用的同步 session)recount_assets(library_id)方法:查询实际数量并修正管理脚本:
scripts/recount_asset_counts.py:支持--dry-run输出差异清单,确认后执行修正测试覆盖(13 个新测试):
🚀 预览环境已部署
🗑️ 预览环境已清理
PR #1787 已关闭或合并,对应的预览环境已被清理。