Skip to content

Commit

Permalink
Merge pull request #35 from aliyun/features/init_entities
Browse files Browse the repository at this point in the history
feat: add pagination support for listing feature entities
  • Loading branch information
bruceding authored Oct 28, 2024
2 parents 2134bc4 + be32f3d commit 490cdfd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
6 changes: 4 additions & 2 deletions api/api_feature_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ FeatureEntityApiService List FeatureEntities
@return InlineResponse20079
*/
func (a *FeatureEntityApiService) ListFeatureEntities(projectId string) (ListFeatureEntitiesResponse, error) {
func (a *FeatureEntityApiService) ListFeatureEntities(pagesize, pagenumber int32, projectId string) (ListFeatureEntitiesResponse, error) {
var (
localVarReturnValue ListFeatureEntitiesResponse
)
request := paifeaturestore.ListFeatureEntitiesRequest{}
request.SetProjectId(projectId)
request.SetPageSize(100)
request.SetPageSize(pagesize)
request.SetPageNumber(pagenumber)

response, err := a.client.ListFeatureEntities(&a.client.instanceId, &request)
if err != nil {
return localVarReturnValue, err
}

localVarReturnValue.TotalCount = int(*response.Body.TotalCount)
var featureEntities []*FeatureEntity

for _, entity := range response.Body.FeatureEntities {
Expand Down
1 change: 1 addition & 0 deletions api/response_feature_entity.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

type ListFeatureEntitiesResponse struct {
TotalCount int `json:"total_count"`
FeatureEntities []*FeatureEntity
}

Expand Down
31 changes: 20 additions & 11 deletions featurestore/feature_store_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,32 @@ func (c *FeatureStoreClient) LoadProjectData() error {
project := domain.NewProject(p, c.datasourceInitClient)
projectData[project.ProjectName] = project

var (
pagesize = 100
pagenumber = 1
)

// get feature entities
listFeatureEntitiesResponse, err := c.client.FeatureEntityApi.ListFeatureEntities(strconv.Itoa(p.ProjectId))
if err != nil {
c.logError(fmt.Errorf("list feature entities error, err=%v", err))
return err
}
for {
listFeatureEntitiesResponse, err := c.client.FeatureEntityApi.ListFeatureEntities(int32(pagesize), int32(pagenumber), strconv.Itoa(p.ProjectId))
if err != nil {
c.logError(fmt.Errorf("list feature entities error, err=%v", err))
return err
}

for _, entity := range listFeatureEntitiesResponse.FeatureEntities {
if entity.ProjectId == project.ProjectId {
for _, entity := range listFeatureEntitiesResponse.FeatureEntities {
project.FeatureEntityMap[entity.FeatureEntityName] = domain.NewFeatureEntity(entity)
}

if len(listFeatureEntitiesResponse.FeatureEntities) == 0 || pagesize*pagenumber > listFeatureEntitiesResponse.TotalCount {
break
}

pagenumber++

}

var (
pagesize = 100
pagenumber = 1
)
pagenumber = 1
// get feature views
for {
listFeatureViews, err := c.client.FeatureViewApi.ListFeatureViews(int32(pagesize), int32(pagenumber), strconv.Itoa(p.ProjectId))
Expand Down

0 comments on commit 490cdfd

Please sign in to comment.