{"id":13445388,"date":"2020-09-23T18:02:06","date_gmt":"2020-09-23T18:02:06","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/hyperdb-revisiting\/"},"modified":"2020-09-23T18:02:06","modified_gmt":"2020-09-23T18:02:06","slug":"hyperdb-revisiting","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/hyperdb-revisiting\/","title":{"rendered":"HyperDB (revisiting)"},"content":{"rendered":"<p>In reference to this, which is closed and (probably) should not be:<\/p>\n<p>https:\/\/wordpress.org\/support\/topic\/incompatible-with-hyperdb-and-sql_calc_found_rows-deprecation\/<\/p>\n<p>The problem here is two fold.  HyperDB itself doesn&#8217;t check for anything between SELECT and SQL_CALC_ROWS_FOUND (in this case you use DISTINCT), which in itself may be an issue (I asked over there).<\/p>\n<p>I have fixed this incompatibility by simply updating the preg in hyperDB and modifying EM to look for the hyperdb flag ($wpdb-&gt;last_found_rows_result) set for automatic SELECT ROWS_FOUND() when using SQL_CALC_FOUND_ROWS.  For example, in classes\/em-events.php around line 215:<\/p>\n<p>self::$num_rows_found = $wpdb-&gt;last_found_rows_result ? $wpdb-&gt;last_found_rows_result : $wpdb-&gt;get_var(&#8216;SELECT FOUND_ROWS()&#8217;);<\/p>\n<p>You could integrate easily with HyperDB in this sort of case, but you&#8217;d have to drop the DISTINCT.<\/p>\n<p>On the other hand, ya&#8217;ll should abandon this method (SQL_CALC_FOUND_ROWS) altogether as it&#8217;s deprecated by MySQL.  Just run a second select query for COUNT(*) in this if\/then statement rather than SELECT FOUND_ROWS() altogether &#8212; in the event pagination was even needed (I don&#8217;t think I&#8217;m even using it actually).  I&#8217;d rather just mod one plugin rather than yours and HyperDB, but this fix is actually quicker in my case than trying to sort out your logic for post counting \/ pagination.<\/p>\n<p>My solution sucks since it would require HyperDB to fix their own dealings with SQL_CALC_FOUND_ROWS not allowing statements between it and SELECT (which I think is likely faulty to begin with since it doesn&#8217;t follow valid SQL syntax, but maybe there&#8217;s some sage-like reason).  Alas, a plugin as popular as yours should probably not be outright incompatible with Automattic&#8217;s own DB extension they use widely on their own clustering solutions, but that&#8217;s a different matter.<\/p>\n<p>Either case, I can&#8217;t use read-write split replication servers via HyperDB with Events Manager and that throws a gear in my cogs =P<\/p>\n<p>It&#8217;s been 9 months since the aforementioned post, would be nice to get an update on the matter.<\/p>\n","protected":false},"template":"","class_list":["post-13445388","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13445388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13445388\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13445388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}