Skip to content

Commit

Permalink
fix: [AH-578]: Fixed Sort By DownloadCount | Gitness (#3217)
Browse files Browse the repository at this point in the history
* fix: [AH-578]: Fixed Sort By DownloadCount
* fix: [AH-578]: Fixed Sort By DownloadCount
* fix: [AH-578]: Fixed Sort By DownloadCount
  • Loading branch information
ritek01 authored and Harness committed Jan 3, 2025
1 parent 03a064b commit dec251e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions registry/app/api/controller/metadata/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var artifactSortMap = map[string]string{
"repoKey": "name",
"lastModified": "updated_at",
"name": "image_name",
"downloadsCount": "image_name",
"downloadsCount": "download_count",
"createdAt": "created_at",
}

Expand All @@ -88,7 +88,7 @@ var artifactVersionSortMap = map[string]string{
"name": "name",
"size": "name",
"pullCommand": "name",
"downloadsCount": "name",
"downloadsCount": "download_count",
"lastModified": "updated_at",
"createdAt": "created_at",
}
Expand Down
21 changes: 16 additions & 5 deletions registry/app/store/database/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
greaterThan string = ">"
labelSeparatorStart string = "%^_"
labelSeparatorEnd string = "^_%"
downloadCount string = "download_count"
)

type tagDao struct {
Expand Down Expand Up @@ -399,8 +400,11 @@ func (t tagDao) GetAllArtifactsByParentID(
if search != "" {
q = q.Where("tag_image_name LIKE ?", sqlPartialMatch(search))
}

q = q.OrderBy("tag_" + sortByField + " " + sortByOrder).Limit(uint64(limit)).Offset(uint64(offset))
sortField := "tag_" + sortByField
if sortByField == downloadCount {
sortField = downloadCount
}
q = q.OrderBy(sortField + " " + sortByOrder).Limit(uint64(limit)).Offset(uint64(offset))

sql, args, err := q.ToSql()
if err != nil {
Expand Down Expand Up @@ -754,7 +758,11 @@ func (t tagDao) GetAllArtifactsByRepo(
q = q.Where("'^_' || ar.image_labels || '^_' LIKE ?", labelsVal)
}

q = q.OrderBy("t.tag_" + sortByField + " " + sortByOrder).Limit(uint64(limit)).Offset(uint64(offset))
sortField := "t.tag_" + sortByField
if sortByField == downloadCount {
sortField = downloadCount
}
q = q.OrderBy(sortField + " " + sortByOrder).Limit(uint64(limit)).Offset(uint64(offset))

sql, args, err := q.ToSql()
if err != nil {
Expand Down Expand Up @@ -860,8 +868,11 @@ func (t tagDao) GetAllTagsByRepoAndImage(
if search != "" {
q = q.Where("tag_name LIKE ?", sqlPartialMatch(search))
}

q = q.OrderBy("tag_" + sortByField + " " + sortByOrder).Limit(uint64(limit)).Offset(uint64(offset))
sortField := "tag_" + sortByField
if sortByField == downloadCount {
sortField = downloadCount
}
q = q.OrderBy(sortField + " " + sortByOrder).Limit(uint64(limit)).Offset(uint64(offset))

sql, args, err := q.ToSql()
if err != nil {
Expand Down

0 comments on commit dec251e

Please sign in to comment.