Skip to content

Commit

Permalink
🐛 TechDependencies deduplicated with direct taking priority. (#573)
Browse files Browse the repository at this point in the history
TechDependencies deduplicated with direct taking priority.
The solution is to sort the dependencies with DIRECT first. Then relax
the Create() to ignore dups on conflict.
The dependencies are not a memory concern.

fixes: #572

---------

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored Dec 5, 2023
1 parent 0ecb271 commit 82174a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (h AnalysisHandler) AppCreate(ctx *gin.Context) {
_ = ctx.Error(err)
return
}
var deps []*TechDependency
for {
r := &TechDependency{}
err = d.Decode(r)
Expand All @@ -365,8 +366,15 @@ func (h AnalysisHandler) AppCreate(ctx *gin.Context) {
return
}
}
deps = append(deps, r)
}
sort.Slice(deps, func(i, _ int) bool {
return !deps[i].Indirect
})
for _, r := range deps {
m := r.Model()
m.AnalysisID = analysis.ID
db := db.Clauses(clause.OnConflict{DoNothing: true})
err = db.Create(m).Error
if err != nil {
_ = ctx.Error(err)
Expand Down
4 changes: 4 additions & 0 deletions hack/add/analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ name: github.com/java
indirect: "true"
version: 8
" >> ${file}
echo -n "---
name: github.com/java
version: 8
" >> ${file}
#
# Analysis
#
Expand Down

0 comments on commit 82174a2

Please sign in to comment.