diff --git a/pkg/daemon/gc/gc_artifact.go b/pkg/daemon/gc/gc_artifact.go index ce69068c..e1be4c9c 100644 --- a/pkg/daemon/gc/gc_artifact.go +++ b/pkg/daemon/gc/gc_artifact.go @@ -226,12 +226,15 @@ func (g gcArtifact) deleteArtifactCheck() { continue } // 3. check manifest index associate with this artifact - err = artifactService.IsArtifactAssociatedWithArtifact(g.ctx, task.Artifact.ID) - if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - log.Error().Err(err).Int64("repositoryID", task.Artifact.RepositoryID).Int64("artifactID", task.Artifact.ID).Msg("Get manifest associated with manifest index failed") - } - if err == nil { - continue + if !(task.Artifact.ContentType == "application/vnd.docker.distribution.manifest.list.v2+json" || + task.Artifact.ContentType == "application/vnd.oci.image.index.v1+json") { // skip this check if artifact is manifest index + err = artifactService.IsArtifactAssociatedWithArtifact(g.ctx, task.Artifact.ID) + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + log.Error().Err(err).Int64("repositoryID", task.Artifact.RepositoryID).Int64("artifactID", task.Artifact.ID).Msg("Get manifest associated with manifest index failed") + } + if err == nil { + continue + } } // 4. delete the artifact that referrer to this artifact delArtifacts, err := artifactService.GetReferrers(g.ctx, task.Artifact.RepositoryID, task.Artifact.Digest, nil) diff --git a/pkg/dal/dao/artifact.go b/pkg/dal/dao/artifact.go index 5453e288..7bed5d16 100644 --- a/pkg/dal/dao/artifact.go +++ b/pkg/dal/dao/artifact.go @@ -121,10 +121,10 @@ func (s *artifactService) Create(ctx context.Context, artifact *models.Artifact) // FindWithLastPull ... func (s *artifactService) FindWithLastPull(ctx context.Context, repositoryID int64, before int64, limit, last int64) ([]*models.Artifact, error) { return s.tx.Artifact.WithContext(ctx). + Where(s.tx.Artifact.ID.Gt(last), s.tx.Artifact.RepositoryID.Eq(repositoryID)). Where(s.tx.Artifact.LastPull.Lt(before)). Or(s.tx.Artifact.LastPull.IsNull(), s.tx.Artifact.UpdatedAt.Lt(before)). - Where(s.tx.Artifact.ID.Gt(last), s.tx.Artifact.RepositoryID.Eq(repositoryID)). - Limit(int(limit)).Find() + Limit(int(limit)).Order(s.tx.Artifact.ID).Find() } // FindAssociateWithTag ... diff --git a/pkg/dal/dao/blob.go b/pkg/dal/dao/blob.go index 5e2a8ff8..2c2120ad 100644 --- a/pkg/dal/dao/blob.go +++ b/pkg/dal/dao/blob.go @@ -88,7 +88,7 @@ func (s *blobService) FindWithLastPull(ctx context.Context, before int64, last, Where(s.tx.Blob.ID.Gt(last)). Where(s.tx.Blob.LastPull.Lt(before)). Or(s.tx.Blob.LastPull.IsNull(), s.tx.Blob.UpdatedAt.Lt(before)). - Find() + Order(s.tx.Blob.ID).Find() } // FindAssociateWithArtifact ... diff --git a/pkg/dal/models/artifact.go b/pkg/dal/models/artifact.go index 2ecc0434..649f9e2b 100644 --- a/pkg/dal/models/artifact.go +++ b/pkg/dal/models/artifact.go @@ -71,7 +71,7 @@ type ArtifactSizeByNamespaceOrRepository interface { // ArtifactAssociated ... type ArtifactAssociated interface { - // SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_index_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=@artifactID + // SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=@artifactID ArtifactAssociated(artifactID int64) (gen.M, error) } diff --git a/pkg/dal/query/artifacts.gen.go b/pkg/dal/query/artifacts.gen.go index eb530431..c4dfe4ef 100644 --- a/pkg/dal/query/artifacts.gen.go +++ b/pkg/dal/query/artifacts.gen.go @@ -1011,13 +1011,13 @@ func (a artifactDo) ArtifactSizeByRepository(repositoryID int64) (result models. return } -// SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_index_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=@artifactID +// SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=@artifactID func (a artifactDo) ArtifactAssociated(artifactID int64) (result map[string]interface{}, err error) { var params []interface{} var generateSQL strings.Builder params = append(params, artifactID) - generateSQL.WriteString("SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_index_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=? ") + generateSQL.WriteString("SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=? ") result = make(map[string]interface{}) var executeSQL *gorm.DB