On a website with ca. 180k users, they made some performance tests using New Relic and they found that each time a "Create New User" Toolset Form is submitted, a huge query is run twice, resulting in a 20 seconds lead-time.
The query run twice is:
SELECT DISTINCT meta_key FROM wp_usermeta WHERE meta_key NOT LIKE 'wpcf-%' AND meta_key NOT LIKE '\\\\_%' LIMIT 512
The query comes from function getCustomFieldsList in cred-frontend-editor/library/toolset/cred/embedded/models/UserFields.php
I checked that code and found that the results of this inefficient query are supposed to be saved in the Datbase, as a transient called cred_transient_usermeta_keys_visible512, expiring weekly.
That would at least avoid the hugely inefficient query to be run each time the form is used, however, that transient is never saved.
Thus, the code runs each time the form is used.
Not sure why the transient is never saved.
When I checked I could only find the Views counterpart to this same thing which is wpv_transient_usermeta_keys_visible512
Note that I can save other transients just fine on this website, so its not due to cache or else site-related fault. Something in Toolset Forms seems to simply not save the transient for whatever reason. Thus, the SQL query runs each time.
But even if the transient would be saved, the real issue wouldn't be resolved, just hidden:
That SQL query is not exactly the definition of performant.
If a website has just a couple thousand entries then this might be no issue, but with 180k users as here this quickly becomes a nightmare, even if limited to 512 results.
Anything we can do here?
Let's remember that this all happens when a new user is created with a form, and I am pretty positive we don't need to know each field in the Datbase "not starting with a wpcf- prefix" to create a new user (also not the first 512).
Something is fishy with that query to start with - why is it there?
Shouldn't this be a pure backend thing, used for where we can control non-cred fields with Toolset?
(I might be wrong, but that is what it seems to be: a query to get non-toolset fields. Surely we do not want to run that on forms in the front end where we already know what fields the form will be including?)
Cheers!