Skip to content

Commit 0bf035a

Browse files
authored
Merge pull request #691 from riyaa14/registrants
Filter out connections which are not registrants
2 parents dd02423 + 3d0b57a commit 0bf035a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

models/meshmodel/registry/registry.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package registry
22

33
import (
44
"fmt"
5+
"strings"
6+
"sync"
7+
"time"
8+
59
"github.com/gofrs/uuid"
610
"github.com/layer5io/meshkit/database"
711
models "github.com/layer5io/meshkit/models/meshmodel/core/v1beta1"
@@ -14,9 +18,6 @@ import (
1418
"golang.org/x/text/cases"
1519
"golang.org/x/text/language"
1620
"gorm.io/gorm/clause"
17-
"strings"
18-
"sync"
19-
"time"
2021
)
2122

2223
// MeshModelRegistrantData struct defines the body of the POST request that is sent to the capability
@@ -174,11 +175,11 @@ func (rm *RegistryManager) GetRegistrant(e entity.Entity) connection.Connection
174175
// to be removed
175176
func (rm *RegistryManager) GetRegistrants(f *models.HostFilter) ([]models.MeshModelHostsWithEntitySummary, int64, error) {
176177
var result []models.MesheryHostSummaryDB
177-
var totalcount int64
178+
var totalConnectionsCount int64
178179
db := rm.db
179180

180181
query := db.Table("connections c").
181-
Count(&totalcount).
182+
Count(&totalConnectionsCount).
182183
Select("c.*, " +
183184
"COUNT(CASE WHEN r.type = 'component' THEN 1 END) AS components, " +
184185
"COUNT(CASE WHEN r.type = 'model' THEN 1 END) AS models," +
@@ -213,8 +214,14 @@ func (rm *RegistryManager) GetRegistrants(f *models.HostFilter) ([]models.MeshMo
213214
}
214215

215216
var response []models.MeshModelHostsWithEntitySummary
216-
217+
nonRegistantCount := int64(0)
217218
for _, r := range result {
219+
220+
if r.Models == 0 {
221+
nonRegistantCount++
222+
continue
223+
}
224+
218225
res := models.MeshModelHostsWithEntitySummary{
219226
Connection: r.Connection,
220227
Summary: models.EntitySummary{
@@ -226,7 +233,9 @@ func (rm *RegistryManager) GetRegistrants(f *models.HostFilter) ([]models.MeshMo
226233
response = append(response, res)
227234
}
228235

229-
return response, totalcount, nil
236+
registrantCount := (totalConnectionsCount - nonRegistantCount)
237+
238+
return response, registrantCount, nil
230239
}
231240

232241
func (rm *RegistryManager) GetEntities(f entity.Filter) ([]entity.Entity, int64, int, error) {

0 commit comments

Comments
 (0)