Skip to content

Commit

Permalink
fix label select db session
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Feb 28, 2024
1 parent de2da94 commit fae826a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.21.0

- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21
go-version: 1.21.0

- name: Checkout Code
uses: actions/checkout@v3
Expand Down
14 changes: 8 additions & 6 deletions core/service/common/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"fmt"
"strings"

"gorm.io/gorm"

"github.com/99nil/gopkg/sets"

storageV1 "github.com/zc2638/ink/pkg/api/storage/v1"
Expand All @@ -31,7 +33,9 @@ func SelectNamesByLabels(ctx context.Context, kind, namespace string, labels map
}

db := database.FromContext(ctx)
db = db.Model(&storageV1.Label{}).Where(&storageV1.Label{Namespace: namespace, Kind: kind})
db = db.Model(&storageV1.Label{}).
Where(&storageV1.Label{Namespace: namespace, Kind: kind}).
Session(&gorm.Session{})

var start bool
nameSet := sets.New[string]()
Expand All @@ -46,11 +50,9 @@ func SelectNamesByLabels(ctx context.Context, kind, namespace string, labels map
nameSet.Add(selectNames...)
continue
}
for _, sn := range selectNames {
if !nameSet.Has(sn) {
nameSet.Remove(sn)
}
}

selectNameSet := sets.New(selectNames...)
nameSet = nameSet.Intersection(selectNameSet)
if nameSet.Len() == 0 {
return nil, nil
}
Expand Down

0 comments on commit fae826a

Please sign in to comment.