diff --git a/services/registry/registry_svc.go b/services/registry/registry_svc.go index 8a325b6..bfa31eb 100644 --- a/services/registry/registry_svc.go +++ b/services/registry/registry_svc.go @@ -471,14 +471,10 @@ 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) @@ -486,6 +482,14 @@ func (s *RegistryService) ListNodeVersions( 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))