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 committed Mar 28, 2024
1 parent fe0a884 commit ea52c29
Show file tree
Hide file tree
Showing 2 changed files with 18 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
20 changes: 16 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,24 @@ func VersionFiles(ctx context.Context, _ client.Client, input *generated.Version
return objectInfoList[i].LastModified.After(objectInfoList[j].LastModified)
})

existMap := make(map[string]int)
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 keyword == "" || strings.Contains(obj.Key, keyword) {
existMap[obj.Key] += 1
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 ea52c29

Please sign in to comment.