{"id":1379252,"date":"2017-11-09T10:51:47","date_gmt":"2017-11-09T18:51:47","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/"},"modified":"2017-11-09T10:51:47","modified_gmt":"2017-11-09T18:51:47","slug":"performance-issue","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/","title":{"rendered":"Performance issue"},"content":{"rendered":"<p>Hello,<\/p>\n<p>After the last update I suffered a huge impact on the performance of my site. I analyzed the slow queries executed by mysql, and I found that the following function is having a terrible impact on the performance, with queries that need several minutes to be executed:<\/p>\n<pre><code>\npublic function get_min_max_coords() {\n\t\tglobal $wpdb;\n\n\t\t\/** @var Tribe__Cache $cache *\/\n\t\t$cache  = tribe( &#039;cache&#039; );\n\t\t$coords = $cache-&gt;get_transient( self::ESTIMATION_CACHE_KEY, &#039;save_post&#039; );\n\n\t\t\/\/ We have a cached value!\n\t\tif ( is_array( $coords ) ) {\n\t\t\treturn $coords;\n\t\t}\n\n\t\t\/\/ Since we are just getting the IDs this is rather performant.\n\t\t$published_events_query = tribe_get_events(\n\t\t\tarray(\n\t\t\t\t&#039;post_type&#039;      =&gt; Tribe__Events__Main::POSTTYPE,\n\t\t\t\t&#039;posts_per_page&#039; =&gt; - 1,\n\t\t\t\t&#039;fields&#039;         =&gt; &#039;ids&#039;,\n\t\t\t\t&#039;orderby&#039;        =&gt; &#039;none&#039;,\n\t\t\t)\n\t\t);\n\n\t\t$event_ids_prepared = implode( &#039;, &#039;, $published_events_query );\n\t\t$latitude_key = self::LAT;\n\t\t$longitude_key = self::LNG;\n\n\t\t$sql = &quot;\n\t\t\tSELECT\n\t\t\t\tMAX( &lt;code&gt;coords&lt;\/code&gt;.&lt;code&gt;lat&lt;\/code&gt; ) AS &lt;code&gt;max_lat&lt;\/code&gt;,\n\t\t\t\tMAX( &lt;code&gt;coords&lt;\/code&gt;.&lt;code&gt;lng&lt;\/code&gt; ) AS &lt;code&gt;max_lng&lt;\/code&gt;,\n\t\t\t\tMIN( &lt;code&gt;coords&lt;\/code&gt;.&lt;code&gt;lat&lt;\/code&gt; ) AS &lt;code&gt;min_lat&lt;\/code&gt;,\n\t\t\t\tMIN( &lt;code&gt;coords&lt;\/code&gt;.&lt;code&gt;lng&lt;\/code&gt; ) AS &lt;code&gt;min_lng&lt;\/code&gt;\n\t\t\tFROM (\n\t\t\t\tSELECT &lt;code&gt;post_id&lt;\/code&gt; AS &lt;code&gt;venue_id&lt;\/code&gt;,\n\t\t\t\tCASE\n\t\t\t\t\tWHEN &lt;code&gt;meta_key&lt;\/code&gt; = &#039;{$latitude_key}&#039;\n\t\t\t\t\tTHEN CAST( &lt;code&gt;meta_value&lt;\/code&gt; AS DECIMAL( 10, 6 ) )\n\t\t\t\tEND AS &lt;code&gt;lat&lt;\/code&gt;,\n\t\t\t\tCASE\n\t\t\t\t\tWHEN &lt;code&gt;meta_key&lt;\/code&gt; = &#039;{$longitude_key}&#039;\n\t\t\t\t\tTHEN CAST( &lt;code&gt;meta_value&lt;\/code&gt; AS DECIMAL( 10, 6 ) )\n\t\t\t\tEND AS &lt;code&gt;lng&lt;\/code&gt;\n\t\t\tFROM &lt;code&gt;{$wpdb-&gt;postmeta}&lt;\/code&gt;\n\t\t\tWHERE\n\t\t\t\t(\n\t\t\t\t\t&lt;code&gt;meta_key&lt;\/code&gt; = &#039;{$latitude_key}&#039;\n\t\t\t\t\tOR &lt;code&gt;meta_key&lt;\/code&gt; = &#039;{$longitude_key}&#039;\n\t\t\t\t)\n\t\t\t\tAND &lt;code&gt;post_id&lt;\/code&gt; IN (\n\t\t\t\t\tSELECT &lt;code&gt;meta_value&lt;\/code&gt;\n\t\t\t\t\tFROM &lt;code&gt;{$wpdb-&gt;postmeta}&lt;\/code&gt;\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t&lt;code&gt;meta_key&lt;\/code&gt; = &#039;_EventVenueID&#039;\n\t\t\t\t\t\tAND &lt;code&gt;post_id&lt;\/code&gt; IN ( {$event_ids_prepared} )\n\t\t\t\t)\n\t\t\t) AS &lt;code&gt;coords&lt;\/code&gt;\n\t\t&quot;;\n\n\t\t$data = $wpdb-&gt;get_row( $sql, ARRAY_A );\n\n\t\tif ( ! empty( $data ) ) {\n\t\t\t\/\/ If there is no geoloc data then each result will be null - we cannot pass null values\n\t\t\t\/\/ to the Google Maps API however\n\t\t\t$data = array_map( &#039;floatval&#039;, $data );\n\t\t}\n\n\t\t$cache-&gt;set_transient( self::ESTIMATION_CACHE_KEY, $data, 86400, &#039;save_post&#039; );\n\n\t\treturn $data;\n\t}\n<\/code><\/pre>\n<p>Please, consider a system where we have several hundreds or even thousands of events.<\/p>\n<p>Am I right with this issue? Do you have any solution for this?<\/p>\n<p>Kind regards,<\/p>\n<p>Pablo<\/p>\n","protected":false},"template":"","class_list":["post-1379252","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Performance issue -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Performance issue -\" \/>\n<meta property=\"og:description\" content=\"Hello, After the last update I suffered a huge impact on the performance of my site. I analyzed the slow queries executed by mysql, and I found that the following function is having a terrible impact on the performance, with queries that need several minutes to be executed: public function get_min_max_coords() { global $wpdb; \/** [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/\",\"name\":\"Performance issue -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-11-09T18:51:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Events Calendar PRO\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Performance issue\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Performance issue -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/","og_locale":"en_US","og_type":"article","og_title":"Performance issue -","og_description":"Hello, After the last update I suffered a huge impact on the performance of my site. I analyzed the slow queries executed by mysql, and I found that the following function is having a terrible impact on the performance, with queries that need several minutes to be executed: public function get_min_max_coords() { global $wpdb; \/** [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/","name":"Performance issue -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-11-09T18:51:47+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/performance-issue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Events Calendar PRO","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/"},{"@type":"ListItem","position":5,"name":"Performance issue"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1379252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1379252\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1379252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}