Skip to content

Commit

Permalink
Revert "Add counts to model, relationship and component"
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-kumar09 authored May 16, 2023
1 parent bfea649 commit c4fa2b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
7 changes: 2 additions & 5 deletions models/meshmodel/core/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func CreateComponent(db *database.Handler, c ComponentDefinition) (uuid.UUID, er
err = db.Create(&cdb).Error
return c.ID, err
}
func GetMeshModelComponents(db *database.Handler, f ComponentFilter) (c []ComponentDefinition, count int64) {
func GetMeshModelComponents(db *database.Handler, f ComponentFilter) (c []ComponentDefinition) {
type componentDefinitionWithModel struct {
ComponentDefinitionDB
ModelDB
Expand Down Expand Up @@ -127,9 +127,6 @@ func GetMeshModelComponents(db *database.Handler, f ComponentFilter) (c []Compon
finder = finder.Order(f.OrderOn)
}
}

finder.Count(&count)

finder = finder.Offset(f.Offset)
if f.Limit != 0 {
finder = finder.Limit(f.Limit)
Expand All @@ -146,7 +143,7 @@ func GetMeshModelComponents(db *database.Handler, f ComponentFilter) (c []Compon
c = append(c, cm.ComponentDefinitionDB.GetComponentDefinition(cm.ModelDB.GetModel(cm.CategoryDB.GetCategory(db))))
}

return c, count
return c
}

type ComponentFilter struct {
Expand Down
7 changes: 2 additions & 5 deletions models/meshmodel/core/v1alpha1/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (rf *RelationshipFilter) Create(m map[string]interface{}) {
return
}
}
func GetMeshModelRelationship(db *database.Handler, f RelationshipFilter) (r []RelationshipDefinition, count int64) {
func GetMeshModelRelationship(db *database.Handler, f RelationshipFilter) (r []RelationshipDefinition) {
type componentDefinitionWithModel struct {
RelationshipDefinitionDB
ModelDB
Expand Down Expand Up @@ -92,9 +92,6 @@ func GetMeshModelRelationship(db *database.Handler, f RelationshipFilter) (r []R
finder = finder.Order(f.OrderOn)
}
}

finder.Count(&count)

finder = finder.Offset(f.Offset)
if f.Limit != 0 {
finder = finder.Limit(f.Limit)
Expand All @@ -107,7 +104,7 @@ func GetMeshModelRelationship(db *database.Handler, f RelationshipFilter) (r []R
for _, cm := range componentDefinitionsWithModel {
r = append(r, cm.RelationshipDefinitionDB.GetRelationshipDefinition(cm.ModelDB.GetModel(cm.CategoryDB.GetCategory(db))))
}
return r, count
return r
}

func (rdb *RelationshipDefinitionDB) GetRelationshipDefinition(m Model) (r RelationshipDefinition) {
Expand Down
26 changes: 9 additions & 17 deletions models/meshmodel/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,34 +157,34 @@ func (rm *RegistryManager) RegisterEntity(h Host, en Entity) error {
}
}

func (rm *RegistryManager) GetEntities(f types.Filter) ([]Entity, *int64) {
func (rm *RegistryManager) GetEntities(f types.Filter) []Entity {
switch filter := f.(type) {
case *v1alpha1.ComponentFilter:
en := make([]Entity, 0)
comps, count := v1alpha1.GetMeshModelComponents(rm.db, *filter)
comps := v1alpha1.GetMeshModelComponents(rm.db, *filter)
for _, comp := range comps {
en = append(en, comp)
}
return en, &count
return en
case *v1alpha1.RelationshipFilter:
en := make([]Entity, 0)
relationships, count := v1alpha1.GetMeshModelRelationship(rm.db, *filter)
relationships := v1alpha1.GetMeshModelRelationship(rm.db, *filter)
for _, rel := range relationships {
en = append(en, rel)
}
return en, &count
return en
case *v1alpha1.PolicyFilter:
en := make([]Entity, 0)
policies := v1alpha1.GetMeshModelPolicy(rm.db, *filter)
for _, pol := range policies {
en = append(en, pol)
}
return en, nil
return en
default:
return nil, nil
return nil
}
}
func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1alpha1.Model, int64) {
func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) []v1alpha1.Model {
var m []v1alpha1.Model
type modelWithCategories struct {
v1alpha1.ModelDB
Expand All @@ -195,10 +195,6 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
finder := db.Model(&v1alpha1.ModelDB{}).
Select("model_dbs.*, category_dbs.*").
Joins("JOIN category_dbs ON model_dbs.category_id = category_dbs.id") //

// total count before pagination
var count int64

if mf, ok := f.(*v1alpha1.ModelFilter); ok {
if mf.Greedy {
if mf.Name != "" && mf.DisplayName != "" {
Expand Down Expand Up @@ -229,9 +225,6 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
finder = finder.Order(mf.OrderOn)
}
}

finder.Count(&count)

if mf.Limit != 0 {
finder = finder.Limit(mf.Limit)
}
Expand All @@ -248,8 +241,7 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
for _, modelDB := range modelWithCategoriess {
m = append(m, modelDB.ModelDB.GetModel(modelDB.GetCategory(db)))
}

return m, count
return m
}
func (rm *RegistryManager) GetCategories(db *database.Handler, f types.Filter) []v1alpha1.Category {
var catdb []v1alpha1.CategoryDB
Expand Down

0 comments on commit c4fa2b7

Please sign in to comment.