mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +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")
|
aggregateQuery.addColumn("COUNT(DISTINCT temp.id) as total")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - this doesn't work yet
|
if options.Megapixels {
|
||||||
// if options.Megapixels {
|
query.addJoins(
|
||||||
// query.addColumn("COALESCE(images.width, 0) * COALESCE(images.height, 0) / 1000000 as megapixels")
|
join{
|
||||||
// aggregateQuery.addColumn("COALESCE(SUM(temp.megapixels), 0) as megapixels")
|
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 {
|
if options.TotalSize {
|
||||||
// query.addColumn("COALESCE(images.size, 0) as size")
|
query.addJoins(
|
||||||
// aggregateQuery.addColumn("COALESCE(SUM(temp.size), 0) as size")
|
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
|
const includeSortPagination = false
|
||||||
aggregateQuery.from = fmt.Sprintf("(%s) as temp", query.toSQL(includeSortPagination))
|
aggregateQuery.from = fmt.Sprintf("(%s) as temp", query.toSQL(includeSortPagination))
|
||||||
|
|
||||||
out := struct {
|
out := struct {
|
||||||
Total int
|
Total int
|
||||||
Megapixels float64
|
Megapixels null.Float
|
||||||
Size float64
|
Size null.Float
|
||||||
}{}
|
}{}
|
||||||
if err := qb.repository.queryStruct(ctx, aggregateQuery.toSQL(includeSortPagination), query.args, &out); err != nil {
|
if err := qb.repository.queryStruct(ctx, aggregateQuery.toSQL(includeSortPagination), query.args, &out); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -826,8 +845,8 @@ func (qb *ImageStore) queryGroupedFields(ctx context.Context, options models.Ima
|
|||||||
|
|
||||||
ret := models.NewImageQueryResult(qb)
|
ret := models.NewImageQueryResult(qb)
|
||||||
ret.Count = out.Total
|
ret.Count = out.Total
|
||||||
ret.Megapixels = out.Megapixels
|
ret.Megapixels = out.Megapixels.Float64
|
||||||
ret.TotalSize = out.Size
|
ret.TotalSize = out.Size.Float64
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user