Skip to content

Commit

Permalink
Merge pull request #1474 from memphisdev/bugfix-RND-256-new-endpoint-…
Browse files Browse the repository at this point in the history
…to-clean-disconnected-producers-consumers

fix
  • Loading branch information
shohamroditimemphis committed Dec 4, 2023
2 parents d4c3006 + 7f7387d commit 6ed8fa7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
14 changes: 7 additions & 7 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2701,12 +2701,12 @@ func GetNotDeletedProducersByStationID(stationId int) ([]models.Producer, error)
}
return producers, nil
}
func GetAllProducersByStationID(stationId int) ([]models.ExtendedProducerRes, error) {
func GetAllProducersByStationID(stationId int) ([]models.ExtendedProducer, error) {
ctx, cancelfunc := context.WithTimeout(context.Background(), DbOperationTimeout*time.Second)
defer cancelfunc()
conn, err := MetadataDbClient.Client.Acquire(ctx)
if err != nil {
return []models.ExtendedProducerRes{}, err
return []models.ExtendedProducer{}, err
}
defer conn.Release()
query := `SELECT
Expand All @@ -2727,20 +2727,20 @@ LIMIT 5000;
`
stmt, err := conn.Conn().Prepare(ctx, "get_producers_by_station_id", query)
if err != nil {
return []models.ExtendedProducerRes{}, err
return []models.ExtendedProducer{}, err
}
rows, err := conn.Conn().Query(ctx, stmt.Name, stationId)
if err != nil {
return []models.ExtendedProducerRes{}, err
return []models.ExtendedProducer{}, err
}
defer rows.Close()

producers, err := pgx.CollectRows(rows, pgx.RowToStructByPos[models.ExtendedProducerRes])
producers, err := pgx.CollectRows(rows, pgx.RowToStructByPos[models.ExtendedProducer])
if err != nil {
return []models.ExtendedProducerRes{}, err
return []models.ExtendedProducer{}, err
}
if len(producers) == 0 {
return []models.ExtendedProducerRes{}, nil
return []models.ExtendedProducer{}, nil
}
return producers, nil
}
Expand Down
11 changes: 0 additions & 11 deletions models/producers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ type Producer struct {
}

type ExtendedProducer struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
ConnectionId string `json:"connection_id,omitempty"`
UpdatedAt time.Time `json:"created_at"`
StationName string `json:"station_name"`
IsActive bool `json:"is_active"`
Count int `json:"count"`
}

type ExtendedProducerRes struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
Expand Down
22 changes: 3 additions & 19 deletions server/memphis_handlers_producers.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (ph ProducersHandler) GetProducersByStation(station models.Station) ([]mode
continue
}

producerExtendedRes := models.ExtendedProducerRes{
producerExtendedRes := models.ExtendedProducer{
ID: producer.ID,
Name: producer.Name,
StationName: producer.StationName,
Expand All @@ -277,25 +277,9 @@ func (ph ProducersHandler) GetProducersByStation(station models.Station) ([]mode

producersNames = append(producersNames, producer.Name)
if producer.IsActive {
producerRes := models.ExtendedProducer{
ID: producerExtendedRes.ID,
Name: producerExtendedRes.Name,
StationName: producerExtendedRes.StationName,
UpdatedAt: producerExtendedRes.UpdatedAt,
IsActive: producerExtendedRes.IsActive,
Count: producerExtendedRes.ConnectedProducersCount,
}
connectedProducers = append(connectedProducers, producerRes)
connectedProducers = append(connectedProducers, producerExtendedRes)
} else {
producerRes := models.ExtendedProducer{
ID: producerExtendedRes.ID,
Name: producerExtendedRes.Name,
StationName: producerExtendedRes.StationName,
UpdatedAt: producerExtendedRes.UpdatedAt,
IsActive: producerExtendedRes.IsActive,
Count: producerExtendedRes.DisconnedtedProducersCount,
}
disconnectedProducers = append(disconnectedProducers, producerRes)
disconnectedProducers = append(disconnectedProducers, producerExtendedRes)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ const ProduceConsumList = ({ producer }) => {
<OverflowTip text={row.name} width={'100px'}>
{row.name}
</OverflowTip>
<OverflowTip text={row.count} width={'70px'}>
{row.count}
<OverflowTip text={row.connected_producers_count} width={'70px'}>
{row.connected_producers_count}
</OverflowTip>
<span className="status-icon" style={{ width: '38px' }}>
<StatusIndication is_active={row.is_active} is_deleted={row.is_active} />
Expand Down

0 comments on commit 6ed8fa7

Please sign in to comment.