You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/07/06 18:30:30 UTC
[GitHub] elsloo closed pull request #2505: remove nested sql call in
cachegroup read
elsloo closed pull request #2505: remove nested sql call in cachegroup read
URL: https://github.com/apache/trafficcontrol/pull/2505
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/lib/go-tc/v13/cachegroups.go b/lib/go-tc/v13/cachegroups.go
index df1562f27..d053db482 100644
--- a/lib/go-tc/v13/cachegroups.go
+++ b/lib/go-tc/v13/cachegroups.go
@@ -36,11 +36,11 @@ type CacheGroup struct {
ShortName string `json:"shortName" db:"short_name"`
Latitude float64 `json:"latitude" db:"latitude"`
Longitude float64 `json:"longitude" db:"longitude"`
- ParentName string `json:"parentCachegroupName"`
+ ParentName string `json:"parentCachegroupName" db:"parent_cachegroup_name"`
ParentCachegroupID int `json:"parentCachegroupId" db:"parent_cachegroup_id"`
- SecondaryParentName string `json:"secondaryParentCachegroupName"`
+ SecondaryParentName string `json:"secondaryParentCachegroupName" db:"secondary_parent_cachegroup_name"`
SecondaryParentCachegroupID int `json:"secondaryParentCachegroupId" db:"secondary_parent_cachegroup_id"`
- FallbackToClosest bool `json:"fallbackToClosest" db:"fallback_to_closest`
+ FallbackToClosest bool `json:"fallbackToClosest" db:"fallback_to_closest"`
Type string `json:"typeName" db:"type_name"` // aliased to type_name to disambiguate struct scans due to join on 'type' table
TypeID int `json:"typeId" db:"type_id"` // aliased to type_id to disambiguate struct scans due join on 'type' table
LastUpdated tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
@@ -52,9 +52,9 @@ type CacheGroupNullable struct {
ShortName *string `json:"shortName" db:"short_name"`
Latitude *float64 `json:"latitude" db:"latitude"`
Longitude *float64 `json:"longitude"db:"longitude"`
- ParentName *string `json:"parentCachegroupName"`
+ ParentName *string `json:"parentCachegroupName" db:"parent_cachegroup_name"`
ParentCachegroupID *int `json:"parentCachegroupId" db:"parent_cachegroup_id"`
- SecondaryParentName *string `json:"secondaryParentCachegroupName"`
+ SecondaryParentName *string `json:"secondaryParentCachegroupName" db:"secondary_parent_cachegroup_name"`
SecondaryParentCachegroupID *int `json:"secondaryParentCachegroupId" db:"secondary_parent_cachegroup_id"`
FallbackToClosest *bool `json:"fallbackToClosest" db:"fallback_to_closest"`
Type *string `json:"typeName" db:"type_name"` // aliased to type_name to disambiguate struct scans due to join on 'type' table
diff --git a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
index c84e329f9..4c538563d 100644
--- a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
+++ b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
@@ -201,38 +201,6 @@ func getParentCachegroupIDs(tx *sqlx.Tx, cachegroup *TOCacheGroup) error {
return nil
}
-// looks up the parent and secondary cachegroup names by cachegroup ID.
-// the names are set on the struct.
-//
-// used by Read()
-func getParentCacheGroupNames(tx *sqlx.Tx, cachegroup *TOCacheGroup) error {
- query1 := `SELECT name FROM cachegroup where id=$1`
- var primaryName string
- var secondaryName string
-
- // primary parent lookup
- if cachegroup.ParentCachegroupID != nil {
- err := tx.QueryRow(query1, *cachegroup.ParentCachegroupID).Scan(&primaryName)
- if err != nil {
- log.Errorf("received error: %++v from query execution", err)
- return err
- }
- cachegroup.ParentName = &primaryName
- }
-
- // secondary parent lookup
- if cachegroup.SecondaryParentCachegroupID != nil {
- err := tx.QueryRow(query1, *cachegroup.SecondaryParentCachegroupID).Scan(&secondaryName)
- if err != nil {
- log.Errorf("received error: %++v from query execution", err)
- return err
- }
- cachegroup.SecondaryParentName = &secondaryName
- }
-
- return nil
-}
-
//The TOCacheGroup implementation of the Creator interface
//all implementations of Creator should use transactions and return the proper errorType
//ParsePQUniqueConstraintError is used to determine if a cachegroup with conflicting values exists
@@ -317,7 +285,6 @@ func (cg *TOCacheGroup) Read(parameters map[string]string) ([]interface{}, []err
log.Errorf("error parsing CacheGroup rows: %v", err)
return nil, []error{tc.DBError}, tc.SystemError
}
- getParentCacheGroupNames(cg.ReqInfo.Tx, &s)
CacheGroups = append(CacheGroups, s)
}
@@ -445,12 +412,16 @@ cachegroup.short_name,
cachegroup.latitude,
cachegroup.longitude,
cachegroup.parent_cachegroup_id,
+cgp.name AS parent_cachegroup_name,
cachegroup.secondary_parent_cachegroup_id,
+cgs.name AS secondary_parent_cachegroup_name,
type.name AS type_name,
cachegroup.type AS type_id,
cachegroup.last_updated
FROM cachegroup
-INNER JOIN type ON cachegroup.type = type.id`
+INNER JOIN type ON cachegroup.type = type.id
+LEFT JOIN cachegroup AS cgp ON cachegroup.parent_cachegroup_id = cgp.id
+LEFT JOIN cachegroup AS cgs ON cachegroup.secondary_parent_cachegroup_id = cgs.id`
return query
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services