mysql - wp_usermeta query hanging for a few seconds before loading -


I have a question that I wrote a few years ago for a membership website. I'm not very well-versed in using $ wpdb (or mysql code in general) to write a custom query, and the site has grown quite a bit. Now there are about 150k rows in the wp_usermeta table, and the page where the query is loading, is hanging for the first two seconds. I hope this time will get worse and the site will benefit more users.

Any help to help you to speed up this query will be greatly appreciated.

  $ Paged = (get_query_var ('paged'))? Get_query_var ('paged'): 1; $ Range = 15; $ Offset = ($ paged - 1) * $ border; $ Key = 'first_name'; $ Sql ​​= "SELECT SQL_CALC_FOUND_ROWS {$ wpdb- & gt; User}. * To {$ wpdb-> User} INNER JOIN {$ wpdb-> USBITA} wp_usermeta ON ({$ wpdb- & gt; User} .id = wp_usermeta .user_id) where 1 = 1 and wp_usermeta.meta_key = '$ k' and wp_usermeta.meta_value  Get_results ($ sql); $ Found_rows = $ wpdb- & gt; Get_var ("SELECT FOUND_ROWS ();"); Foreach ($ member $ members) {// display member info here}  

* Note: I'm paginating ... not displaying all the results on a page.

"post-text" itemprop = "text">

Here are some things.

First of all, you order by the user's first name, but not recovering or displaying it is a little weird. You can order by wp_users.user_nicename, and skip joining wp_usermeta. There will be some time left to join this. The value of that column is set by the user in his profile, and reflects the identity by which he wants to know. Therefore, this is a proper ordering column, most likely.

Second, you are retrieving all columns (*) in wp_users. Can you avoid retrieving them all, and really can not require it? It will save time in sorting.

Your query will do this.

  $ sql = "Select $ {wpdb-> and; user} WHERE user_registered & lt; '2014-01-30' ORDER BY from SQL_CALC_FOUND_ROWS id, user_login, user_nicoiname, etc. etc. User_nonymous ASC LIMIT $ offset, $ border ";  

You are stuck, because you want to get a large number of users, with some inevitable inefficiency. But it should be better than you.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -