Skip to content

Commit

Permalink
fix: correct the totalCount value returned by the listModels API
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy committed Jan 2, 2024
1 parent a2fd073 commit cf7a14c
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions apiserver/pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,40 +229,25 @@ func ListModels(ctx context.Context, c dynamic.Interface, input generated.ListMo
models.Items = append(systemModels.Items, models.Items...)
}

totalCount := len(models.Items)

result := make([]generated.PageNode, 0, pageSize)
pageStart := (page - 1) * pageSize
for index, u := range models.Items {
// skip if smaller than the start index
if index < pageStart {
continue
}

result := make([]generated.PageNode, 0, len(models.Items))
for _, u := range models.Items {
m := obj2model(&u)
// filter based on `keyword`
if keyword != "" {
if !strings.Contains(m.Name, keyword) && !strings.Contains(*m.DisplayName, keyword) {
continue
}
if keyword != "" && !strings.Contains(m.Name, keyword) && !strings.Contains(*m.DisplayName, keyword) {
continue
}
result = append(result, m)

// break if page size matches
if len(result) == pageSize {
break
}
}

totalCount := len(result)
pageStart := (page - 1) * pageSize
end := page * pageSize
if end > totalCount {
end = totalCount
}

return &generated.PaginatedResult{
TotalCount: totalCount,
HasNextPage: end < totalCount,
Nodes: result,
Nodes: result[pageStart:end],
}, nil
}

Expand Down

0 comments on commit cf7a14c

Please sign in to comment.