Skip to content

Commit

Permalink
feat: add latestVersion field of VersionedDataset.files
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy committed Apr 10, 2024
1 parent ff9f9d1 commit 8f58c79
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
58 changes: 58 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.

2 changes: 2 additions & 0 deletions apiserver/graph/schema/versioned_dataset.gql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ query getVersionedDataset($name: String!, $namespace: String!, $fileInput: FileF
count
size
versions
latestVersion
creationTimestamp
}
}
Expand Down Expand Up @@ -98,6 +99,7 @@ query listVersionedDatasets($input: ListVersionedDatasetInput!, $fileInput: File
count
size
versions
latestVersion
creationTimestamp
}
}
Expand Down
5 changes: 5 additions & 0 deletions apiserver/graph/schema/versioned_dataset.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ type F {
文件版本列表
"""
versions: [String!]

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

"""
Expand Down
16 changes: 6 additions & 10 deletions apiserver/pkg/versioneddataset/versioned_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,23 @@ 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 {
if !obj.IsLatest || obj.IsDeleteMarker {
continue
}
if keyword == "" || strings.Contains(obj.Key, keyword) {
existMap[obj.Key] = struct{}{}
lastModifiedTime := obj.LastModified
versionID := obj.VersionID
tf := generated.F{
Path: strings.TrimPrefix(obj.Key, prefix),
Time: &lastModifiedTime,
Versions: objMap[obj.Key],
Path: strings.TrimPrefix(obj.Key, prefix),
Time: &lastModifiedTime,
Versions: objMap[obj.Key],
LatestVersion: &versionID,
}

size := utils.BytesToSizedStr(obj.Size)
Expand Down

0 comments on commit 8f58c79

Please sign in to comment.