Skip to content

Commit

Permalink
Debug list node versions (#117)
Browse files Browse the repository at this point in the history
* Add additional logging statement + handle maximum pageSize for listNodeVersions endpoint

* Fix the pagination logic

---------

Co-authored-by: James Kwon <[email protected]>
  • Loading branch information
james03160927 and james03160927 authored Jan 4, 2025
1 parent 2a4d620 commit ef6aa27
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions services/registry/registry_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,21 +471,25 @@ func (s *RegistryService) ListNodeVersions(
}

if filter.MinAge > 0 {
log.Ctx(ctx).Info().Msgf("listing node versions with min age: %v", filter.MinAge)
query.Where(nodeversion.CreateTimeLT(time.Now().Add(-filter.MinAge)))
}

// Apply pagination
if filter.Page > 0 && filter.PageSize > 0 {
query.Offset((filter.Page - 1) * filter.PageSize).Limit(filter.PageSize)
}

// Note: custom SELECT statement cause errors in the ent framework when using the Count method.
// We need to include the logic to exclude certain fields after the count query is executed.
total, err := query.Count(ctx)
if err != nil {
return nil, fmt.Errorf("failed to count node versions: %w", err)
}

// Apply pagination
// Note: the pagination logic needs to be applied after the count query is executed
if filter.Page > 0 && filter.PageSize > 0 {
log.Ctx(ctx).Info().Msgf(
"listing node versions with pagination: page %v, limit %v", filter.Page, filter.PageSize)
query.Offset((filter.Page - 1) * filter.PageSize).Limit(filter.PageSize)
}

// By default, we are selecting all fields. If the status reason is not required, we will exclude it
if !filter.IncludeStatusReason {
columns := make([]string, 0, len(nodeversion.Columns))
Expand Down

0 comments on commit ef6aa27

Please sign in to comment.