Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENT] fix issue with index on artifact #1835

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/testing/backend/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ func TestArtifacts(t *testing.T) {
Digest: "7a8f47318e4676dacb0142afa0b83029cd7befd9",
}},
wantErr: false,
}, {
name: "sha-1",
artifactInput: &model.ArtifactInputSpec{
Algorithm: "SHA-1",
Digest: "7A8F47318E4676DACB0142AFA0B83029CD7BEFD9",
},
artifactSpec: &model.ArtifactSpec{
Algorithm: ptrfrom.String("SHA-1"),
Digest: ptrfrom.String("7A8F47318E4676DACB0142AFA0B83029CD7BEFD9"),
},
want: []*model.Artifact{{
Algorithm: "sha-1",
Digest: "7a8f47318e4676dacb0142afa0b83029cd7befd9",
}},
wantErr: false,
}, {
name: "sha512",
artifactInput: &model.ArtifactInputSpec{
Expand Down
3 changes: 1 addition & 2 deletions pkg/assembler/backends/arangodb/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func init() {

func initIndex(name string, fields []string, unique bool) index {
return index{
name: name,
name: name,
fields: fields,
unique: unique,
}
Expand Down Expand Up @@ -514,7 +514,6 @@ func getCollectionIndexMap() map[string][]index {
collectionIndexMap := make(map[string][]index)

collectionIndexMap[artifactsStr] = []index{
initIndex("byDigest", []string{"digest"}, true),
mihaimaruseac marked this conversation as resolved.
Show resolved Hide resolved
initIndex("byArtAndDigest", []string{"algorithm", "digest"}, true),
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/assembler/backends/ent/backend/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func upsertBulkArtifact(ctx context.Context, tx *ent.Tx, artInputs []*model.IDor
batches := chunk(artInputs, MaxBatchSize)
ids := make([]string, 0)

conflictColumns := []string{artifact.FieldAlgorithm, artifact.FieldDigest}

for _, artifacts := range batches {
creates := make([]*ent.ArtifactCreate, len(artifacts))
for i, art := range artifacts {
Expand All @@ -108,7 +110,7 @@ func upsertBulkArtifact(ctx context.Context, tx *ent.Tx, artInputs []*model.IDor

err := tx.Artifact.CreateBulk(creates...).
OnConflict(
sql.ConflictColumns(artifact.FieldDigest),
mihaimaruseac marked this conversation as resolved.
Show resolved Hide resolved
sql.ConflictColumns(conflictColumns...),
).
DoNothing().
Exec(ctx)
Expand All @@ -128,11 +130,14 @@ func generateArtifactCreate(tx *ent.Tx, artifactID *uuid.UUID, art *model.IDorAr
}

func upsertArtifact(ctx context.Context, tx *ent.Tx, art *model.IDorArtifactInput) (*string, error) {

conflictColumns := []string{artifact.FieldAlgorithm, artifact.FieldDigest}

artifactID := generateUUIDKey([]byte(helpers.GetKey[*model.ArtifactInputSpec, string](art.ArtifactInput, helpers.ArtifactServerKey)))
insert := generateArtifactCreate(tx, &artifactID, art)
err := insert.
OnConflict(
sql.ConflictColumns(artifact.FieldDigest),
sql.ConflictColumns(conflictColumns...),
).
DoNothing().
Exec(ctx)
Expand Down
9 changes: 2 additions & 7 deletions pkg/assembler/backends/ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/assembler/backends/ent/schema/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (Artifact) Edges() []ent.Edge {
// to query all artifacts using a specific algorithm.
func (Artifact) Indexes() []ent.Index {
return []ent.Index{
index.Fields("algorithm"),
index.Fields("digest").Unique(),
index.Fields("algorithm", "digest").Unique(),
}
}
Loading