mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): support order by snapshot (#24036)
This commit is contained in:
@@ -147,6 +147,7 @@ type SnapshotPolicyListInput struct {
|
||||
// 按绑定的磁盘数量排序
|
||||
// pattern:asc|desc
|
||||
OrderByBindDiskCount string `json:"order_by_bind_disk_count"`
|
||||
OrderBySnapshotCount string `json:"order_by_snapshot_count"`
|
||||
// 按类型过滤
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
@@ -698,6 +698,22 @@ func (manager *SSnapshotPolicyManager) OrderByExtraFields(
|
||||
q = q.AppendField(sdSQ.Field("disk_count"))
|
||||
q = db.OrderByFields(q, []string{input.OrderByBindDiskCount}, []sqlchemy.IQueryField{q.Field("disk_count")})
|
||||
}
|
||||
|
||||
if db.NeedOrderQuery([]string{input.OrderBySnapshotCount}) {
|
||||
spSQ := SnapshotPolicyResourceManager.Query().Equals("resource_type", api.SNAPSHOT_POLICY_TYPE_DISK).SubQuery()
|
||||
ssq := SnapshotManager.Query().SubQuery()
|
||||
pQ := spSQ.Query(
|
||||
spSQ.Field("snapshotpolicy_id"),
|
||||
sqlchemy.COUNT("snapshot_count", ssq.Field("id")),
|
||||
).Join(ssq, sqlchemy.Equals(ssq.Field("disk_id"), spSQ.Field("resource_id"))).GroupBy(spSQ.Field("snapshotpolicy_id"))
|
||||
|
||||
pq := pQ.SubQuery()
|
||||
|
||||
q = q.LeftJoin(pq, sqlchemy.Equals(pq.Field("snapshotpolicy_id"), q.Field("id")))
|
||||
q = q.AppendField(q.QueryFields()...)
|
||||
q = q.AppendField(pq.Field("snapshot_count"))
|
||||
q = db.OrderByFields(q, []string{input.OrderBySnapshotCount}, []sqlchemy.IQueryField{q.Field("snapshot_count")})
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ type SnapshotPolicyListOptions struct {
|
||||
options.BaseListOptions
|
||||
|
||||
OrderByBindDiskCount string
|
||||
OrderBySnapshotCount string
|
||||
}
|
||||
|
||||
func (opts *SnapshotPolicyListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
Reference in New Issue
Block a user