mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Fix images total megapixels and filesize queries (#4203)
This commit is contained in:
@@ -801,24 +801,43 @@ func (qb *ImageStore) queryGroupedFields(ctx context.Context, options models.Ima
|
||||
aggregateQuery.addColumn("COUNT(DISTINCT temp.id) as total")
|
||||
}
|
||||
|
||||
// TODO - this doesn't work yet
|
||||
// if options.Megapixels {
|
||||
// query.addColumn("COALESCE(images.width, 0) * COALESCE(images.height, 0) / 1000000 as megapixels")
|
||||
// aggregateQuery.addColumn("COALESCE(SUM(temp.megapixels), 0) as megapixels")
|
||||
// }
|
||||
if options.Megapixels {
|
||||
query.addJoins(
|
||||
join{
|
||||
table: imagesFilesTable,
|
||||
onClause: "images_files.image_id = images.id",
|
||||
},
|
||||
join{
|
||||
table: imageFileTable,
|
||||
onClause: "images_files.file_id = image_files.file_id",
|
||||
},
|
||||
)
|
||||
query.addColumn("COALESCE(image_files.width, 0) * COALESCE(image_files.height, 0) as megapixels")
|
||||
aggregateQuery.addColumn("COALESCE(SUM(temp.megapixels), 0) / 1000000 as megapixels")
|
||||
}
|
||||
|
||||
// if options.TotalSize {
|
||||
// query.addColumn("COALESCE(images.size, 0) as size")
|
||||
// aggregateQuery.addColumn("COALESCE(SUM(temp.size), 0) as size")
|
||||
// }
|
||||
if options.TotalSize {
|
||||
query.addJoins(
|
||||
join{
|
||||
table: imagesFilesTable,
|
||||
onClause: "images_files.image_id = images.id",
|
||||
},
|
||||
join{
|
||||
table: fileTable,
|
||||
onClause: "images_files.file_id = files.id",
|
||||
},
|
||||
)
|
||||
query.addColumn("COALESCE(files.size, 0) as size")
|
||||
aggregateQuery.addColumn("SUM(temp.size) as size")
|
||||
}
|
||||
|
||||
const includeSortPagination = false
|
||||
aggregateQuery.from = fmt.Sprintf("(%s) as temp", query.toSQL(includeSortPagination))
|
||||
|
||||
out := struct {
|
||||
Total int
|
||||
Megapixels float64
|
||||
Size float64
|
||||
Megapixels null.Float
|
||||
Size null.Float
|
||||
}{}
|
||||
if err := qb.repository.queryStruct(ctx, aggregateQuery.toSQL(includeSortPagination), query.args, &out); err != nil {
|
||||
return nil, err
|
||||
@@ -826,8 +845,8 @@ func (qb *ImageStore) queryGroupedFields(ctx context.Context, options models.Ima
|
||||
|
||||
ret := models.NewImageQueryResult(qb)
|
||||
ret.Count = out.Total
|
||||
ret.Megapixels = out.Megapixels
|
||||
ret.TotalSize = out.Size
|
||||
ret.Megapixels = out.Megapixels.Float64
|
||||
ret.TotalSize = out.Size.Float64
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user