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 29, 2024
1 parent de2da94 commit 647ed23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 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 @@ -24,7 +24,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
version: v1.54.2

- name: Test
run: make tests
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 647ed23

Please sign in to comment.