Skip to content

Commit

Permalink
feat: versioneddataset return the versions field of the file
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy authored and bjwswang committed Mar 29, 2024
1 parent fc3ffd9 commit 2eb96ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apiserver/graph/schema/versioned_dataset.gql
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ query getVersionedDataset($name: String!, $namespace: String!, $fileInput: FileF
fileType
count
size
versions
creationTimestamp
}
}
Expand Down Expand Up @@ -96,6 +97,7 @@ query listVersionedDatasets($input: ListVersionedDatasetInput!, $fileInput: File
fileType
count
size
versions
creationTimestamp
}
}
Expand Down
23 changes: 19 additions & 4 deletions apiserver/pkg/versioneddataset/versioned_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 2eb96ca

Please sign in to comment.