Skip to content

Commit

Permalink
Merge pull request #288 from 0xff-dev/sort-dataset
Browse files Browse the repository at this point in the history
fix: the data list is sorted in reverse order and supports returning …
  • Loading branch information
bjwswang authored Nov 24, 2023
2 parents ccf38ef + 55516c2 commit 59d84d2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/v1alpha1/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const (
// TypeUnknown resources are unknown to the system
TypeUnknown ConditionType = "Unknown"
// TypeDone resources are believed to be processed
TypeDone ConditionType = "Done"
TypeDone ConditionType = "Done"
TypeDataProcessing ConditionType = "DataProcessing"
)

// A ConditionReason represents the reason a resource is in a condition.
Expand Down
1 change: 1 addition & 0 deletions graphql-server/go-server/graph/schema/dataprocessing.gql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ query dataProcessSupportType{
name
zh_name
description
enable
}
}
message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type VersionedDataset {
"""文件的同步状态, Processing或者'' 表示文件正在同步,Succeede 文件同步成功,Failed 存在文件同步失败"""
syncStatus: String

"""数据处理状态,如果为空,表示还没有开始,其他表示"""
"""数据处理状态,如果为空,表示还没有开始,processing 处理中,process_fail处理失败,process_complete处理完成"""
dataProcessStatus: String
}

Expand Down
4 changes: 4 additions & 0 deletions graphql-server/go-server/pkg/dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package dataset
import (
"context"
"fmt"
"sort"
"strings"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -139,6 +140,9 @@ func ListDatasets(ctx context.Context, c dynamic.Interface, input *generated.Lis
if err != nil {
return nil, err
}
sort.Slice(datastList.Items, func(i, j int) bool {
return datastList.Items[i].GetCreationTimestamp().After(datastList.Items[j].GetCreationTimestamp().Time)
})
page, size := 1, 10
if input.Page != nil && *input.Page > 0 {
page = *input.Page
Expand Down
4 changes: 4 additions & 0 deletions graphql-server/go-server/pkg/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package datasource

import (
"context"
"sort"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -191,6 +192,9 @@ func ListDatasources(ctx context.Context, c dynamic.Interface, namespace, labelS
if err != nil {
return nil, err
}
sort.Slice(us.Items, func(i, j int) bool {
return us.Items[i].GetCreationTimestamp().After(us.Items[j].GetCreationTimestamp().Time)
})
result := make([]*model.Datasource, len(us.Items))
for idx, u := range us.Items {
result[idx] = datasource2model(&u)
Expand Down
4 changes: 4 additions & 0 deletions graphql-server/go-server/pkg/embedder/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package embedder

import (
"context"
"sort"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -161,6 +162,9 @@ func ListEmbedders(ctx context.Context, c dynamic.Interface, namespace, labelSel
if err != nil {
return nil, err
}
sort.Slice(us.Items, func(i, j int) bool {
return us.Items[i].GetCreationTimestamp().After(us.Items[j].GetCreationTimestamp().Time)
})
result := make([]*model.Embedder, len(us.Items))
for idx, u := range us.Items {
result[idx] = embedder2model(&u)
Expand Down
4 changes: 4 additions & 0 deletions graphql-server/go-server/pkg/knowledgebase/knowledgebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package knowledgebase

import (
"context"
"sort"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -184,6 +185,9 @@ func ListKnowledgeBases(ctx context.Context, c dynamic.Interface, namespace, lab
if err != nil {
return nil, err
}
sort.Slice(us.Items, func(i, j int) bool {
return us.Items[i].GetCreationTimestamp().After(us.Items[j].GetCreationTimestamp().Time)
})
result := make([]*model.KnowledgeBase, len(us.Items))
for idx, u := range us.Items {
result[idx] = knowledgebase2model(&u)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package versioneddataset
import (
"context"
"fmt"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -87,6 +88,10 @@ func versionedDataset2model(obj *unstructured.Unstructured) (*generated.Versione
syncStatus := string(cond.Reason)
vds.SyncStatus = &syncStatus
}
if cond.Type == v1alpha1.TypeDataProcessing {
dataProcessStatus := string(cond.Reason)
vds.DataProcessStatus = &dataProcessStatus
}
if !cond.LastTransitionTime.IsZero() {
if first || vds.UpdateTimestamp.Before(cond.LastSuccessfulTime.Time) {
vds.UpdateTimestamp = &cond.LastTransitionTime.Time
Expand All @@ -110,6 +115,10 @@ func VersionFiles(ctx context.Context, c dynamic.Interface, input *generated.Ver
keyword = *filter.Keyword
}
objectInfoList := minioutils.ListObjectCompleteInfo(ctx, input.Namespace, prefix, minioClient, -1)
sort.Slice(objectInfoList, func(i, j int) bool {
return objectInfoList[i].LastModified.After(objectInfoList[j].LastModified)
})

result := make([]generated.PageNode, 0)
for _, obj := range objectInfoList {
if keyword == "" || strings.Contains(obj.Key, keyword) {
Expand Down

0 comments on commit 59d84d2

Please sign in to comment.