fix: calculate total file size on backend instead of frontend
- Backend returns total_size for all matching versions - Frontend uses backend's total_size instead of computing from current page Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,27 @@ func handleGetAllVersions(c *gin.Context) {
|
||||
var forcedCount int64
|
||||
database.DB.Model(&model.Version{}).Where("application_id IN ? AND update_strategy = ?", appIDs, "forced").Count(&forcedCount)
|
||||
|
||||
// 计算总文件大小
|
||||
var totalSize int64
|
||||
sizeQuery := database.DB.Model(&model.Version{}).Where("application_id IN ?", appIDs)
|
||||
if applicationIDFilter != "" {
|
||||
sizeQuery = sizeQuery.Where("application_id = ?", applicationIDFilter)
|
||||
}
|
||||
if updateStrategyFilter != "" {
|
||||
sizeQuery = sizeQuery.Where("update_strategy = ?", updateStrategyFilter)
|
||||
}
|
||||
if updateTypeFilter != "" {
|
||||
sizeQuery = sizeQuery.Where("update_type = ?", updateTypeFilter)
|
||||
}
|
||||
if updateMethodFilter != "" {
|
||||
sizeQuery = sizeQuery.Where("update_method = ?", updateMethodFilter)
|
||||
}
|
||||
if searchFilter != "" {
|
||||
searchLower := strings.ToLower(searchFilter)
|
||||
sizeQuery = sizeQuery.Where("LOWER(version) LIKE ? OR LOWER(description) LIKE ?", "%"+searchLower+"%", "%"+searchLower+"%")
|
||||
}
|
||||
sizeQuery.Select("COALESCE(SUM(file_size), 0)").Scan(&totalSize)
|
||||
|
||||
query := database.DB.Where("application_id IN ?", appIDs)
|
||||
if applicationIDFilter != "" {
|
||||
query = query.Where("application_id = ?", applicationIDFilter)
|
||||
@@ -190,6 +211,7 @@ func handleGetAllVersions(c *gin.Context) {
|
||||
"versions": result,
|
||||
"total": total,
|
||||
"forced_count": forcedCount,
|
||||
"total_size": totalSize,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user