srijeet0406 commented on a change in pull request #6003:
URL: https://github.com/apache/trafficcontrol/pull/6003#discussion_r685357558
##########
File path: traffic_ops/traffic_ops_golang/profile/profiles.go
##########
@@ -113,19 +113,19 @@ func (prof *TOProfile) Read(h http.Header, useIMS bool)
([]interface{}, error, e
// Query Parameters to Database Query column mappings
// see the fields mapped in the SQL query
queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
- CDNQueryParam: dbhelpers.WhereColumnInfo{Column: "c.id"},
- NameQueryParam: dbhelpers.WhereColumnInfo{Column: "prof.name"},
- IDQueryParam: dbhelpers.WhereColumnInfo{Column: "prof.id",
Checker: api.IsInt},
+ CDNQueryParam: dbhelpers.WhereColumnInfo{Column: "c.id",
Checker: api.IsInt},
+ NameQueryParam: dbhelpers.WhereColumnInfo{Column: "prof.name"},
+ IDQueryParam: dbhelpers.WhereColumnInfo{Column: "prof.id",
Checker: api.IsInt},
+ ParamQueryParam: dbhelpers.WhereColumnInfo{Column:
"pp.parameter", Checker: api.IsInt},
}
where, orderBy, pagination, queryValues, errs :=
dbhelpers.BuildWhereAndOrderByAndPagination(prof.APIInfo().Params,
queryParamsToQueryCols)
// Narrow down if the query parameter is 'param'
-
// TODO add generic where clause to api.GenericRead
if paramValue, ok := prof.APIInfo().Params[ParamQueryParam]; ok {
queryValues["parameter_id"] = paramValue
if len(paramValue) > 0 {
- where += " LEFT JOIN profile_parameter pp ON prof.id =
pp.profile where pp.parameter=:parameter_id"
+ where = " LEFT JOIN profile_parameter pp ON prof.id =
pp.profile " + where + " AND pp.parameter=:parameter_id"
Review comment:
Once you add the `ParamQueryParam` to the `queryParamsToQueryCols`, the
`BuildWhereAndOrderByAndPagination` function will automatically add the `WHERE`
clause to the query, you don't need to modify the `where` variable above.
Instead, what you can do is add just the ` LEFT JOIN profile_parameter pp ON
prof.id = pp.profile` part if the `parameter_id` param is present.
With the current changes, the query comes out to be this:
``
SELECT
prof.description,
prof.id,
prof.last_updated,
prof.name,
prof.routing_disabled,
prof.type,
c.id as cdn,
c.name as cdn_name
FROM profile prof
LEFT JOIN cdn c ON prof.cdn = c.id LEFT JOIN profile_parameter pp ON prof.id
= pp.profile
WHERE pp.parameter=:param AND pp.parameter=:parameter_id
``
We don't need the two `WHERE` clauses in our query. Also, I think the tests
are still failing for API v2 and v3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]