perf(admin): 下推商品资产筛选并统一工作台缓存刷新

This commit is contained in:
yml2213
2026-11-01 20:54:51 +08:00
parent 6056afa436
commit 99899f4f11
8 changed files with 239 additions and 86 deletions
+7 -32
View File
@@ -35,37 +35,6 @@ func (r *Repository) ListAdmin(ctx context.Context, query AdminListQuery) (*Admi
pageSize = 100
}
if hasAdminAssetFilters(query) {
var rows []listingRow
err := r.applyAdminListFilters(r.baseQuery(ctx), query).
Order("l.id DESC").
Scan(&rows).Error
if err != nil {
return nil, err
}
items := filterAdminListings(rowsToDTO(rows), query)
total := int64(len(items))
start := (page - 1) * pageSize
if start < 0 {
start = 0
}
if start >= len(items) {
items = []ListingDTO{}
} else {
end := start + pageSize
if end > len(items) {
end = len(items)
}
items = items[start:end]
}
return &AdminListResult{
Items: items,
Total: total,
Page: page,
PageSize: pageSize,
}, nil
}
db := r.applyAdminListFilters(r.baseQuery(ctx), query)
offset := (page - 1) * pageSize
if offset < 0 {
@@ -82,7 +51,12 @@ func (r *Repository) ListAdmin(ctx context.Context, query AdminListQuery) (*Admi
if page == 1 && len(rows) < pageSize {
total = int64(len(rows))
} else {
countDB := r.applyAdminListFilters(r.db.WithContext(ctx).Table("rental_listings AS l"), query)
countDB := r.applyAdminListFilters(
r.db.WithContext(ctx).
Table("rental_listings AS l").
Joins("JOIN game_accounts AS a ON a.id = l.account_id"),
query,
)
if err := countDB.Count(&total).Error; err != nil {
return nil, err
}
@@ -149,6 +123,7 @@ func (r *Repository) applyAdminListFilters(db *gorm.DB, query AdminListQuery) *g
if query.MaxDeposit != nil {
db = db.Where("l.deposit_amount_cent <= ?", yuanToAdminCent(*query.MaxDeposit))
}
db = applyAdminAssetSQLFilters(db, query)
return db
}