{"id":13589244,"date":"2020-10-28T02:55:08","date_gmt":"2020-10-28T02:55:08","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/slowdown\/"},"modified":"2020-10-28T03:29:34","modified_gmt":"2020-10-28T03:29:34","slug":"slowdown","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/slowdown\/","title":{"rendered":"Slowdown"},"content":{"rendered":"<p>The plugin causes quite the slowdown, even when no shortcode\/widget is used on that page.<br \/>\nFor each request, a routine is called that downloads plugin translation data from WordPress, this can take up to half a second, slowing down everything significantly.<\/p>\n<p><code>find_or_initialize_translation_details<\/code> calls <code>retrieve_translation_details<\/code> on each request, apparently the caching doesn&#8217;t work.<\/p>\n<p>Edit: It doesn&#8217;t work when the locale is <code>de_DE_formal<\/code>, as no such formal is currently available as plugin translation. However, in this case this plugin should not make a request on every single WordPress request! This slows down the site very noticeably.<\/p>\n<p>Edit 2: The fix for this issue is to compare the first part of the locale (aa_BB) and the second part (aa_BB_[CC]) independently when determining the right locale set to use.<\/p>\n<p>Modification of i18nHelper.php; function retrieve_translation_details (l. 258):<\/p>\n<pre><code>\n    private function retrieve_translation_details() {\n        $branch = &#039;\/stable&#039;;\n\n        $locale_id    = $this-&gt;locale;\n        $locale_parts = explode( &#039;_&#039;, $this-&gt;locale );\n        $locale_slug  = &#039;default&#039;;\n        if(count( $locale_parts ) === 3) {\n            $locale_slug = array_pop( $locale_parts );\n            $locale_id   = implode( &#039;_&#039;, $locale_parts );\n        }\n\n        if (!EnvManager::is_plugin_in_production_mode()) {\n            $branch = &#039;\/dev&#039;;\n        }\n        $api_url = &#039;https:\/\/translate.wordpress.org\/api\/projects\/wp-plugins\/&#039; . LWS_PLUGIN_SLUG . $branch;\n        try {\n            Quota::verify(&#039;WordPress.org&#039;, &#039;GET&#039;);\n            $args = array();\n            $args[&#039;user-agent&#039;] = LWS_PLUGIN_AGENT;\n            $args[&#039;timeout&#039;] = get_option(&#039;live_weather_station_system_http_timeout&#039;);\n            $resp = wp_remote_get($api_url, $args);\n            $body = wp_remote_retrieve_body($resp);\n            unset($resp);\n            if ($body) {\n                $body = json_decode($body);\n                $this-&gt;cpt = 0;\n                if (isset($body)) {\n                    foreach ($body-&gt;translation_sets as $set) {\n                        if ($set-&gt;percent_translated &gt;= $this-&gt;percent_min) {\n                            $this-&gt;cpt += 1;\n                        }\n                        if (!property_exists($set, &#039;wp_locale&#039;)) {\n                            continue;\n                        }\n                        if ($locale_id == $set-&gt;wp_locale &amp;&amp; $locale_slug == $set-&gt;slug) {\n                            return $set;\n                        }\n                    }\n                }\n            }\n            return null;\n        }\n        catch (\\Exception $e) {\n            return null;\n        }\n    }\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13589244","topic","type-topic","status-publish","hentry","topic-tag-performance","topic-tag-request","topic-tag-routine","topic-tag-slowdown"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13589244","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":6,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13589244\/revisions"}],"predecessor-version":[{"id":13589309,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13589244\/revisions\/13589309"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13589244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}