From 2eb96cab6c05308093e05c8e7359733f0da82fb1 Mon Sep 17 00:00:00 2001 From: dayuy <973860441@qq.com> Date: Fri, 29 Mar 2024 14:34:52 +0800 Subject: [PATCH] feat: `versioneddataset` return the `versions` field of the file --- apiserver/graph/schema/versioned_dataset.gql | 2 ++ .../pkg/versioneddataset/versioned_dataset.go | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/apiserver/graph/schema/versioned_dataset.gql b/apiserver/graph/schema/versioned_dataset.gql index 9201243d0..2b8ccac66 100644 --- a/apiserver/graph/schema/versioned_dataset.gql +++ b/apiserver/graph/schema/versioned_dataset.gql @@ -57,6 +57,7 @@ query getVersionedDataset($name: String!, $namespace: String!, $fileInput: FileF fileType count size + versions creationTimestamp } } @@ -96,6 +97,7 @@ query listVersionedDatasets($input: ListVersionedDatasetInput!, $fileInput: File fileType count size + versions creationTimestamp } } diff --git a/apiserver/pkg/versioneddataset/versioned_dataset.go b/apiserver/pkg/versioneddataset/versioned_dataset.go index ebdb2d856..4d6e58ea9 100644 --- a/apiserver/pkg/versioneddataset/versioned_dataset.go +++ b/apiserver/pkg/versioneddataset/versioned_dataset.go @@ -113,8 +113,9 @@ func VersionFiles(ctx context.Context, _ client.Client, input *generated.Version return nil, err } anyObjectInfoList, err := oss.ListObjects(ctx, input.Namespace, miniogo.ListObjectsOptions{ - Prefix: prefix, - Recursive: true, + Prefix: prefix, + Recursive: true, + WithVersions: true, }) if err != nil { return nil, err @@ -124,13 +125,27 @@ func VersionFiles(ctx context.Context, _ client.Client, input *generated.Version return objectInfoList[i].LastModified.After(objectInfoList[j].LastModified) }) + existMap := make(map[string]struct{}) + objMap := make(map[string][]string) + for _, obj := range objectInfoList { + objMap[obj.Key] = append(objMap[obj.Key], obj.VersionID) + } + result := make([]generated.PageNode, 0) for _, obj := range objectInfoList { + if _, ok := existMap[obj.Key]; ok { + continue + } + if obj.IsDeleteMarker { + continue + } if keyword == "" || strings.Contains(obj.Key, keyword) { + existMap[obj.Key] = struct{}{} lastModifiedTime := obj.LastModified tf := generated.F{ - Path: strings.TrimPrefix(obj.Key, prefix), - Time: &lastModifiedTime, + Path: strings.TrimPrefix(obj.Key, prefix), + Time: &lastModifiedTime, + Versions: objMap[obj.Key], } size := utils.BytesToSizedStr(obj.Size)