Github user mitchell852 commented on a diff in the pull request:
https://github.com/apache/incubator-trafficcontrol/pull/434#discussion_r110946789
--- Diff: traffic_ops/app/lib/API/User.pm ---
@@ -281,11 +284,14 @@ sub current {
if ( &is_ldap($self) ) {
my $role = $self->db->resultset('Role')->search( { name =>
"read-only" } )->get_column('id')->single;
+ my $user_tenant_id = $self->current_user_tenant();
+ my $user_tenant = defined($user_tenant_id) ?
$self->db->resultset('Tenant')->search( { id => $user_tenant_id }
)->get_column('name')->single : "N/A";
--- End diff --
it will work without prefetch....but it will create N+1 queries. For
example, if you do a query of the TMUser table which returns 100 users and then
you loop thru your results and call $row->tenant->name, it will do 1 query for
each user to fetch the tenant so you end up with 101 queries.
When you use prefetch you join the user table to the tenant table in the
first query so you only end up with 1 query...
1 query is better than 101 :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---