{"id":15472218,"date":"2022-03-18T13:21:53","date_gmt":"2022-03-18T13:21:53","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/in_array-function-performance\/"},"modified":"2022-03-18T13:23:02","modified_gmt":"2022-03-18T13:23:02","slug":"in_array-function-performance","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/in_array-function-performance\/","title":{"rendered":"in_array function performance"},"content":{"rendered":"<p>Hello guys, it is just a suggestion:<\/p>\n<p>On class-swpm-protection-base.php you check if the post is protected using in_array function, on a big portal with thousands posts protected this gonna have a performance issue.<\/p>\n<p>For the future if you think it worst, you could create the array as an associative array, and use isset, to check if the post is protected.<\/p>\n<pre><code>\n$array = [\n &#039;1548&#039; =&gt; 1&#039;,\n &#039;116515&#039; =&gt; 1&#039;,\n &#039;851312&#039; =&gt; 1&#039;,\n &#039;415511&#039; =&gt; 1&#039;,\n &#039;651322&#039; =&gt; 1&#039;,\n &#039;651321&#039; =&gt; 1&#039;,\n];\n\nreturn isset($array[$post_id]);\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-15472218","topic","type-topic","status-publish","hentry","topic-tag-performance"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15472218","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":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15472218\/revisions"}],"predecessor-version":[{"id":15472222,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15472218\/revisions\/15472222"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=15472218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}