Implemented the Roles Controller
A list of Roles to be displayed
An error was displayed and the list of roles is not returned.
If I search for a specific role the role will come back successfully as long as it has a small number of users attached to it. I've found that the issue is related to this controller not taking into consideration that people may have a large number of users.
If I search for a role that has a minimal amount of users then the role will come back correctly. If I search for the role that is attached to all 300k of my users this throws an error. This happens on my local server as well as my production servers. It happens very quickly so it's not timing out.
This causes the initial listing of roles to fail to load and is basically broken.
PHP 7.3.15-3+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Feb 23 2020 07:23:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.15, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.15-3+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
v7.28.3@b0942c391975972b1a54b2dc983e33a239f169a9
Hello @selected-pixel-jameson
If timeout is not the culprit I wonder what is the error displayed?
Best,
Pedro
I have set the timeout on my server to 180 seconds. The response still errors after 15 seconds. There is no log filed within the Laravel log and no response is returned from the server in the http request.
I just get a 500 internal error in the Chrome Console pointing tot he app.js file.

This is a huge piece of functionality for this platform and it's pretty frustrating that it's more or less unusable.
Thanks @selected-pixel-jameson it does paint a better picture.
In regards to app.js - I have no idea what that is, it's definitely not part of Backpack. The default Backpack JS file is bundle.js, so it sounds like you have a custom app.js file that you're loading, and you have a JS error there. Or maybe that the JS is taking so long to load that it commits suicide, that's been known to happen 馃檮 Such a quitter, javascript 馃ぃ
That being said, I have very good news. I've investigated the issue, and it does seem like using the relationship_count column is not optimal in this use case. Using the relationship_count column on a related table with thousands or millions of entries is bound to have slow performance, because it will load those related models on page.
There's an easy way to go around this - instead of using the relationship_count column, you can:
withCount('users') method to append a fake column to the Eloquent result, without loading the users;text column to show users_count instead of using the relationship_count columnThis will reduce the number of loaded Users to... zero. Here's a before&after, you'll notice there's just one User loaded, that's the logged in user:

It's not clear to me whether you've installed our PermissionManager add-on or you're doing something very similar. In any case:
composer update should do it for you;Let me know if this fixes it for you, I'm pretty sure it will. Thanks for letting us know about this issue - we had no idea relationship_column was this inefficient with big tables.
Cheers!
Added a note to the relationship_count docs to make this crystal-clear - https://github.com/Laravel-Backpack/docs/commit/927537aa6758ab0182b40215e7b844ba1aea616f
Now I'm wondering if we should have this column at all, since the text column can do it better. Unfortunately I see no way to change relationship_column to be more performant.
Issue is resolved. Thank you.
Most helpful comment
Hello @selected-pixel-jameson
If timeout is not the culprit I wonder what is the error displayed?
Best,
Pedro