Don't call to legacy auth to get dashboards. (#9297)

Can cause a lot of ldap calls for example.
Should improve dashboard page load time on certain auth methods.

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
This commit is contained in:
Tony Murray
2018-10-06 16:56:22 -05:00
committed by Neil Lathwood
parent d1772ea1f2
commit 7c09f698a4

View File

@@ -1636,31 +1636,16 @@ function get_disks_with_smart($device, $app_id)
*/
function get_dashboards($user_id = null)
{
$user = is_null($user_id) ? Auth::user() : \App\Models\User::find($user_id);
$default = get_user_pref('dashboard');
$dashboards = dbFetchRows(
"SELECT * FROM `dashboards` WHERE dashboards.access > 0 || dashboards.user_id = ?",
array(is_null($user_id) ? LegacyAuth::id() : $user_id)
);
$usernames = array(
LegacyAuth::id() => LegacyAuth::user()->username
);
return \App\Models\Dashboard::allAvailable($user)->with('user')->get()->map(function ($dashboard) use ($default) {
$dash = $dashboard->toArray();
$dash['username'] = $dashboard->user ? $dashboard->user->username : '';
$dash['default'] = $default == $dashboard->dashboard_id;
$result = array();
foreach ($dashboards as $dashboard) {
$duid = $dashboard['user_id'];
if (!isset($usernames[$duid])) {
$user = LegacyAuth::get()->getUser($duid);
$usernames[$duid] = $user['username'];
}
$dashboard['username'] = $usernames[$duid];
$dashboard['default'] = $dashboard['dashboard_id'] == $default;
$result[$dashboard['dashboard_id']] = $dashboard;
}
return $result;
return $dash;
})->keyBy('dashboard_id')->all();
}
/**