JoryHogeveen / view-admin-as

View the WordPress admin as a different role, switch between users, temporarily change your capabilities, set default screen settings for roles, manage your roles and capabilities.
https://wordpress.org/plugins/view-admin-as/
GNU General Public License v2.0
45 stars 4 forks source link

Performance with 1000+ users >> AJAX user search #19

Closed JoryHogeveen closed 6 years ago

JoryHogeveen commented 7 years ago

The plugin runs fine with a lot of users but when other plugins hook into the user capabilities with queries the load time can still be affected heavily.

The options/features below should fix this:

  1. [x] Limit user query to a max of 100 results. This can be changed with the filter: view_admin_as_user_query_limit
  2. [x] When there are more users than the limit (default: 100), switch to AJAX search instead of loading all users.
  3. [x] Option to disable the user view type UI. It is then still possible to switch from the user lists page. #84

Log:

Run tests on a blog with a LOT of users

planetahuevo commented 6 years ago

Tested with more than 5000 users and it just make everything so slow that I need to deactivate it to work. Not useful for that enviroment.

JoryHogeveen commented 6 years ago

Hi @planetahuevo, Thank you for testing! Could you let me know what other plugins you use?

Note: with v1.8 (upcoming) you can disable the users view type in the admin bar. Switching is then still available on the users list page.

planetahuevo commented 6 years ago

Hi! I tested it on a dev site for a big shop, 27 other plugins, woocommerce, etc. When activated it gives me a "not enough memory" error on PHP. I need to increase the memory from 256 to 512 for the plugin to load at all. And even then, the wp-admin is so slow it is not worth it.

I never really used the user view, only the roles view, which I think it would be the most common use. For a shop, it is useful to see it as costumer instead of using the admin or creating a new "demo user" everytime, which is what I am using right now.

I will wait for the 1.8 and give it another go.

Thanks!

JoryHogeveen commented 6 years ago

Hi @planetahuevo

I think another plugin might cause the memory issue. I've made the query so that it loads everything in one query but I did encounter some issues with other plugins. Groups for example is a plugin which still runs a lot of queries when I filter for capabilities.

If you could send me a plugins list of grant me access to the dev installations (by email! info@keraweb.nl) I could take a look at what would cause this.

1.8 can already be downloaded and tested here: https://github.com/JoryHogeveen/view-admin-as/tree/1.8

Thanks! Jory

planetahuevo commented 6 years ago

Well, could be a clash with another plugin, of course, but this one is part of the issue for sure, as this error appear when I activate view as admin. I will send you the list right now.

JoryHogeveen commented 6 years ago

List received! There are some premium plugins in there so I'm not sure if I can debug properly but I do have some ideas what might cause the issue. Any access management plugin usually hooks into the capabilities of a user using it's own filters and possible queries. I think this might be the issue here. Nevertheless, I must find a better way to handle this for large sites since access management is quite common. Let me know when you need the functionality of this plugin, I could create a small patch to fix this issue for you so you can at least continue until 1.8 gets released.

Thanks, Jory

planetahuevo commented 6 years ago

Hi Jory! Nothing urgent at all. Do not worry. I am a great fan of your plugin and it normally works fine, but I saw the opportunity to test it here with big numbers so I did. :)

For big sites like this we have "test users" in place anyway, so it is not a big deal.

Just keep up the great work and when is ready is ready.

Thanks!

JoryHogeveen commented 6 years ago

@planetahuevo I've updated the 1.8 branch.

The user module is refactored to limit the user query to 100 users (this is filterable). When there are more it will switch to AJAX search so the users won't be loaded on every page load but only when you search for them.

I'm thinking of adding a setting UI for these filters and enhance searching with other types (user login, ID, etc) but I think that will have to wait until 1.8.1 or later.

If you have the time, could you test this on your 5000+ users installation? I'm quite confident that this will work quite well! Link: https://github.com/JoryHogeveen/view-admin-as/tree/1.8

Link to PR for info: https://github.com/JoryHogeveen/view-admin-as/pull/78

planetahuevo commented 6 years ago

Hi, I was able to test it today (not too much) and it works as expected. I am sure you can improved it but it is usable right now with the 1.8 branch. Thank you!!

JoryHogeveen commented 6 years ago

Hi @planetahuevo Sorry for my late reply, I did continue on 1.8 a lot and it's now RC3 already. Planning to go live soon!

I am sure you can improved it but it is usable right now with the 1.8 branch.

Please let me know any ideas for improvement! I'm closing this issue as the initial issue itself is resolved.