Skip to content

Commit

Permalink
feat: add the latestVersion field of KnowledgeBase.FileDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy committed Apr 8, 2024
1 parent 5525fc8 commit 8b75f93
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
64 changes: 64 additions & 0 deletions apiserver/graph/generated/generated.go

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

2 changes: 2 additions & 0 deletions apiserver/graph/generated/models_gen.go

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

4 changes: 4 additions & 0 deletions apiserver/graph/schema/knowledgebase.gql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ query listKnowledgeBases($input: ListKnowledgeBaseInput!){
updateTimestamp
timeCost
version
latestVersion
}
}
}
Expand Down Expand Up @@ -100,6 +101,7 @@ query getKnowledgeBase($name: String!, $namespace: String!) {
updateTimestamp
timeCost
version
latestVersion
}
}
}
Expand Down Expand Up @@ -151,6 +153,7 @@ mutation createKnowledgeBase($input: CreateKnowledgeBaseInput!) {
updateTimestamp
timeCost
version
latestVersion
}
}
}
Expand Down Expand Up @@ -202,6 +205,7 @@ mutation updateKnowledgeBase($input: UpdateKnowledgeBaseInput) {
updateTimestamp
timeCost
version
latestVersion
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions apiserver/graph/schema/knowledgebase.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ type filedetail{
文件版本,""或者"null"的情况表示是文件最新版本。
"""
version: String!

"""
文件最新版本
"""
latestVersion: String!
}

"""
Expand Down
24 changes: 24 additions & 0 deletions apiserver/pkg/knowledgebase/knowledgebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ import (
"context"
"errors"
"fmt"
"path/filepath"
"time"

"github.com/minio/minio-go/v7"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kubeagi/arcadia/api/base/v1alpha1"
"github.com/kubeagi/arcadia/apiserver/graph/generated"
pkgclient "github.com/kubeagi/arcadia/apiserver/pkg/client"
"github.com/kubeagi/arcadia/apiserver/pkg/common"
graphqlutils "github.com/kubeagi/arcadia/apiserver/pkg/utils"
"github.com/kubeagi/arcadia/pkg/config"
Expand Down Expand Up @@ -97,12 +100,32 @@ func knowledgebase2model(ctx context.Context, c client.Client, knowledgebase *v1
})
}
if len(knowledgebase.Status.FileGroupDetail) > 0 {
systemClient, _ := pkgclient.GetClient(nil)
oss, _ := common.SystemDatasourceOSS(ctx, systemClient)

for _, filegroupdetail := range knowledgebase.Status.FileGroupDetail {
ns := knowledgebase.Namespace
if filegroupdetail.Source.Namespace != nil {
ns = *filegroupdetail.Source.Namespace
}
var vsBasePath string
if filegroupdetail.Source.Kind == "VersionedDataset" {
versioneddataset := &v1alpha1.VersionedDataset{}
if err := c.Get(ctx, types.NamespacedName{Name: filegroupdetail.Source.Name, Namespace: ns}, versioneddataset); err == nil {
if versioneddataset.Spec.Dataset != nil && versioneddataset.Status.IsReady() {
vsBasePath = filepath.Join("dataset", versioneddataset.Spec.Dataset.Name, versioneddataset.Spec.Version)
}
}
}
for _, detail := range filegroupdetail.FileDetails {
var detailStat minio.ObjectInfo
if vsBasePath != "" && oss != nil {
info := &v1alpha1.OSS{Bucket: ns, Object: filepath.Join(vsBasePath, detail.Path)}
detailInfo, err := oss.StatFile(ctx, info)
if err == nil {
detailStat, _ = detailInfo.(minio.ObjectInfo)
}
}
key := fmt.Sprintf("%s/%s/%s", ns, filegroupdetail.Source.Name, detail.Path)
if v, ok := cache[key]; ok {
filegroupdetails[v[0]].Filedetails[v[1]] = &generated.Filedetail{
Expand All @@ -114,6 +137,7 @@ func knowledgebase2model(ctx context.Context, c client.Client, knowledgebase *v1
TimeCost: int(detail.TimeCost),
UpdateTimestamp: new(time.Time),
Version: detail.Version,
LatestVersion: detailStat.VersionID,
}
*filegroupdetails[v[0]].Filedetails[v[1]].UpdateTimestamp = detail.LastUpdateTime.Time
}
Expand Down

0 comments on commit 8b75f93

Please sign in to comment.