Add "order by" clause to avoid the duplicat rows

Add "order by" clause to avoid the duplicat rows: https://www.postgresql.org/docs/9.6/queries-limit.html

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2020-03-28 11:06:12 +08:00
parent 018469e1a2
commit fb975d902c
4 changed files with 5 additions and 2 deletions

View File

@ -97,6 +97,7 @@ func (d *dao) List(ctx context.Context, query *q.Query) ([]*Artifact, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
qs = qs.OrderBy("-PushTime", "ID")
if _, err = qs.All(&artifacts); err != nil { if _, err = qs.All(&artifacts); err != nil {
return nil, err return nil, err
} }

View File

@ -68,6 +68,7 @@ func (d *dao) List(ctx context.Context, query *q.Query) ([]*models.RepoRecord, e
if err != nil { if err != nil {
return nil, err return nil, err
} }
qs = qs.OrderBy("-CreationTime", "RepositoryID")
if _, err = qs.All(&repositories); err != nil { if _, err = qs.All(&repositories); err != nil {
return nil, err return nil, err
} }

View File

@ -71,6 +71,7 @@ func (d *dao) List(ctx context.Context, query *q.Query) ([]*tag.Tag, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
qs = qs.OrderBy("-PushTime", "ID")
if _, err = qs.All(&tags); err != nil { if _, err = qs.All(&tags); err != nil {
return nil, err return nil, err
} }

View File

@ -80,8 +80,8 @@ class TestProjects(unittest.TestCase):
artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, tag, **TestProjects.USER_CLIENT) artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, tag, **TestProjects.USER_CLIENT)
#6. Verify the image(IA) contains tag named 1.0; #6. Verify the image(IA) contains tag named 1.0;
self.assertEqual(artifact[0].tags[0].name, tag) self.assertEqual(artifact[0].tags[0].name, "1.0")
self.assertEqual(artifact[0].tags[1].name, "1.0") self.assertEqual(artifact[0].tags[1].name, tag)
#7. Delete the tag(1.0) from image(IA); #7. Delete the tag(1.0) from image(IA);
self.artifact.delete_tag(TestProjects.project_name, self.repo_name, tag, "1.0",**TestProjects.USER_CLIENT) self.artifact.delete_tag(TestProjects.project_name, self.repo_name, tag, "1.0",**TestProjects.USER_CLIENT)