feat: optimize the FindUnreferencedPackages package query

Replace a double select with a simple select.

The complication originates from the initial implementation which
deleted packages instead of selecting them. It was justified to
workaround a problem in MySQL. But it is just a waste of resources
when collecting a list of IDs.
This commit is contained in:
Earl Warren 2024-07-27 15:29:53 +02:00
parent dac78913aa
commit ff6aceaeac
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 18 additions and 16 deletions

View file

@ -479,6 +479,8 @@ func TestPackageCleanup(t *testing.T) {
AddBasicAuth(user.Name)
MakeRequest(t, req, http.StatusCreated)
unittest.AssertExistsAndLoadBean(t, &packages_model.Package{Name: "cleanup-test"})
pbs, err := packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, duration)
assert.NoError(t, err)
assert.NotEmpty(t, pbs)
@ -493,6 +495,8 @@ func TestPackageCleanup(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, pbs)
unittest.AssertNotExistsBean(t, &packages_model.Package{Name: "cleanup-test"})
_, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, "cleanup-test", container_model.UploadVersion)
assert.ErrorIs(t, err, packages_model.ErrPackageNotExist)
})