{"action":"created","comment":{"url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments/191427161","pull_request_review_id":123992397,"id":191427161,"diff_hunk":"@@ -26,8 +26,42 @@ public static function get_attachment_by_url( $url ) {\n \t\t\t// @codeCoverageIgnoreEnd -- The rest we _can_ test.\n \t\t}\n \n-\t\t// phpcs:ignore WordPress.VIP.RestrictedFunctions -- We use the WP COM version if we can, see above.\n-\t\treturn (int) attachment_url_to_postid( $url );\n+\t\treturn self::attachment_url_to_postid( $url );\n+\t}\n+\n+\t/**\n+\t * Implements the attachment_url_to_postid with use of WP Cache.\n+\t *\n+\t * @param string $url The attachment URL for which we want to know the Post ID.\n+\t *\n+\t * @return int The Post ID belonging to the attachment, 0 if not found.\n+\t */\n+\tprotected static function attachment_url_to_postid( $url ) {\n+\t\t$cache_key = sprintf( 'yoast_attachment_url_post_id_%s', md5( $url ) );\n+\n+\t\t// Set the id based on the hashed url in the cache.\n+\t\t$id = wp_cache_get( $cache_key );\n+\n+\t\tif ( $id === 'not_found' ) {\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\t// ID is found in cache, return.\n+\t\tif ( $id !== false ) {\n+\t\t\treturn $id;\n+\t\t}\n+\n+\t\t$id = attachment_url_to_postid( $url );","path":"inc/class-wpseo-image-utils.php","position":31,"original_position":31,"commit_id":"85c49873301fad41ddc608a9a9355bccc9006f1d","original_commit_id":"85c49873301fad41ddc608a9a9355bccc9006f1d","user":{"login":"andizer","id":325040,"avatar_url":"https://avatars0.githubusercontent.com/u/325040?v=4","gravatar_id":"","url":"https://api.github.com/users/andizer","html_url":"https://github.com/andizer","followers_url":"https://api.github.com/users/andizer/followers","following_url":"https://api.github.com/users/andizer/following{/other_user}","gists_url":"https://api.github.com/users/andizer/gists{/gist_id}","starred_url":"https://api.github.com/users/andizer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andizer/subscriptions","organizations_url":"https://api.github.com/users/andizer/orgs","repos_url":"https://api.github.com/users/andizer/repos","events_url":"https://api.github.com/users/andizer/events{/privacy}","received_events_url":"https://api.github.com/users/andizer/received_events","type":"User","site_admin":false},"body":"Can you add this comment above this line: \r\n`// phpcs:ignore WordPress.VIP.RestrictedFunctions -- We use the WP COM version if we can, see above.`","created_at":"2018-05-29T13:40:59Z","updated_at":"2018-05-29T13:45:21Z","html_url":"https://github.com/Yoast/wordpress-seo/pull/9715#discussion_r191427161","pull_request_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments/191427161"},"html":{"href":"https://github.com/Yoast/wordpress-seo/pull/9715#discussion_r191427161"},"pull_request":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715"}}},"pull_request":{"url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715","id":188035468,"html_url":"https://github.com/Yoast/wordpress-seo/pull/9715","diff_url":"https://github.com/Yoast/wordpress-seo/pull/9715.diff","patch_url":"https://github.com/Yoast/wordpress-seo/pull/9715.patch","issue_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/9715","number":9715,"state":"open","locked":false,"title":"Changed the amount of images queried to be placed in OG tags: now exits after first suitable image found. ","user":{"login":"Dieterrr","id":16388834,"avatar_url":"https://avatars3.githubusercontent.com/u/16388834?v=4","gravatar_id":"","url":"https://api.github.com/users/Dieterrr","html_url":"https://github.com/Dieterrr","followers_url":"https://api.github.com/users/Dieterrr/followers","following_url":"https://api.github.com/users/Dieterrr/following{/other_user}","gists_url":"https://api.github.com/users/Dieterrr/gists{/gist_id}","starred_url":"https://api.github.com/users/Dieterrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dieterrr/subscriptions","organizations_url":"https://api.github.com/users/Dieterrr/orgs","repos_url":"https://api.github.com/users/Dieterrr/repos","events_url":"https://api.github.com/users/Dieterrr/events{/privacy}","received_events_url":"https://api.github.com/users/Dieterrr/received_events","type":"User","site_admin":false},"body":"## Summary\r\n\r\nThis PR can be summarized in the following changelog entry:\r\n\r\n* Optimises the query selecting a fallback OG image for better performance.  \r\n\r\n## Relevant technical choices:\r\n\r\n* Instead of creating a query to the database for each image on the page and adding all of these images to the og tags, the method now exits after the first image that meets the requirements is found. \r\n* A new function for caching attachment ID's is introduced in the image utils class. \r\n\r\n## Test instructions\r\n\r\nThis PR can be tested by following these steps:\r\n\r\n* Create a page with several images. \r\n* Make sure the page does not have a featured image.\r\n* Make sure this page does not have any social media images configured.\r\n* Open the page/post and right click to open \"view page source\", you should see a `og:image` tag  for each image on the page. \r\n* Switch to this branch and do the same: there should be only one `og:image` tag now.  \r\n\r\n## Quality assurance\r\n\r\n* [x] I have tested this code to the best of my abilities\r\n* [x] I have added unittests to verify the code works as intended\r\n\r\nFixes #9679 \r\n","created_at":"2018-05-15T07:22:06Z","updated_at":"2018-05-29T13:45:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8665f730f887dd3b08432615c234046dcc87ff90","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":44801559,"url":"https://api.github.com/repos/Yoast/wordpress-seo/labels/component:%20social","name":"component: social","color":"006b75","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715/commits","review_comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715/comments","review_comment_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/9715/comments","statuses_url":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/85c49873301fad41ddc608a9a9355bccc9006f1d","head":{"label":"Yoast:9679-more-efficient-detecting-of-og-images","ref":"9679-more-efficient-detecting-of-og-images","sha":"85c49873301fad41ddc608a9a9355bccc9006f1d","user":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"repo":{"id":6723399,"name":"wordpress-seo","full_name":"Yoast/wordpress-seo","owner":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yoast/wordpress-seo","description":"Yoast SEO for WordPress","fork":false,"url":"https://api.github.com/repos/Yoast/wordpress-seo","forks_url":"https://api.github.com/repos/Yoast/wordpress-seo/forks","keys_url":"https://api.github.com/repos/Yoast/wordpress-seo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yoast/wordpress-seo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yoast/wordpress-seo/teams","hooks_url":"https://api.github.com/repos/Yoast/wordpress-seo/hooks","issue_events_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/events{/number}","events_url":"https://api.github.com/repos/Yoast/wordpress-seo/events","assignees_url":"https://api.github.com/repos/Yoast/wordpress-seo/assignees{/user}","branches_url":"https://api.github.com/repos/Yoast/wordpress-seo/branches{/branch}","tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/tags","blobs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/{sha}","languages_url":"https://api.github.com/repos/Yoast/wordpress-seo/languages","stargazers_url":"https://api.github.com/repos/Yoast/wordpress-seo/stargazers","contributors_url":"https://api.github.com/repos/Yoast/wordpress-seo/contributors","subscribers_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscribers","subscription_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscription","commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yoast/wordpress-seo/contents/{+path}","compare_url":"https://api.github.com/repos/Yoast/wordpress-seo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yoast/wordpress-seo/merges","archive_url":"https://api.github.com/repos/Yoast/wordpress-seo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yoast/wordpress-seo/downloads","issues_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues{/number}","pulls_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls{/number}","milestones_url":"https://api.github.com/repos/Yoast/wordpress-seo/milestones{/number}","notifications_url":"https://api.github.com/repos/Yoast/wordpress-seo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yoast/wordpress-seo/labels{/name}","releases_url":"https://api.github.com/repos/Yoast/wordpress-seo/releases{/id}","deployments_url":"https://api.github.com/repos/Yoast/wordpress-seo/deployments","created_at":"2012-11-16T15:16:29Z","updated_at":"2018-05-29T11:38:37Z","pushed_at":"2018-05-29T13:36:54Z","git_url":"git://github.com/Yoast/wordpress-seo.git","ssh_url":"git@github.com:Yoast/wordpress-seo.git","clone_url":"https://github.com/Yoast/wordpress-seo.git","svn_url":"https://github.com/Yoast/wordpress-seo","homepage":"http://yoast.com/wordpress/seo/","size":259340,"stargazers_count":890,"watchers_count":890,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":525,"mirror_url":null,"archived":false,"open_issues_count":1047,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":525,"open_issues":1047,"watchers":890,"default_branch":"trunk"}},"base":{"label":"Yoast:trunk","ref":"trunk","sha":"abb7f7a49329c91aad2fd39e9c43742a518bccef","user":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"repo":{"id":6723399,"name":"wordpress-seo","full_name":"Yoast/wordpress-seo","owner":{"login":"Yoast","id":4690436,"avatar_url":"https://avatars0.githubusercontent.com/u/4690436?v=4","gravatar_id":"","url":"https://api.github.com/users/Yoast","html_url":"https://github.com/Yoast","followers_url":"https://api.github.com/users/Yoast/followers","following_url":"https://api.github.com/users/Yoast/following{/other_user}","gists_url":"https://api.github.com/users/Yoast/gists{/gist_id}","starred_url":"https://api.github.com/users/Yoast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yoast/subscriptions","organizations_url":"https://api.github.com/users/Yoast/orgs","repos_url":"https://api.github.com/users/Yoast/repos","events_url":"https://api.github.com/users/Yoast/events{/privacy}","received_events_url":"https://api.github.com/users/Yoast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yoast/wordpress-seo","description":"Yoast SEO for WordPress","fork":false,"url":"https://api.github.com/repos/Yoast/wordpress-seo","forks_url":"https://api.github.com/repos/Yoast/wordpress-seo/forks","keys_url":"https://api.github.com/repos/Yoast/wordpress-seo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yoast/wordpress-seo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yoast/wordpress-seo/teams","hooks_url":"https://api.github.com/repos/Yoast/wordpress-seo/hooks","issue_events_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/events{/number}","events_url":"https://api.github.com/repos/Yoast/wordpress-seo/events","assignees_url":"https://api.github.com/repos/Yoast/wordpress-seo/assignees{/user}","branches_url":"https://api.github.com/repos/Yoast/wordpress-seo/branches{/branch}","tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/tags","blobs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/{sha}","languages_url":"https://api.github.com/repos/Yoast/wordpress-seo/languages","stargazers_url":"https://api.github.com/repos/Yoast/wordpress-seo/stargazers","contributors_url":"https://api.github.com/repos/Yoast/wordpress-seo/contributors","subscribers_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscribers","subscription_url":"https://api.github.com/repos/Yoast/wordpress-seo/subscription","commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yoast/wordpress-seo/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yoast/wordpress-seo/contents/{+path}","compare_url":"https://api.github.com/repos/Yoast/wordpress-seo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yoast/wordpress-seo/merges","archive_url":"https://api.github.com/repos/Yoast/wordpress-seo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yoast/wordpress-seo/downloads","issues_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues{/number}","pulls_url":"https://api.github.com/repos/Yoast/wordpress-seo/pulls{/number}","milestones_url":"https://api.github.com/repos/Yoast/wordpress-seo/milestones{/number}","notifications_url":"https://api.github.com/repos/Yoast/wordpress-seo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yoast/wordpress-seo/labels{/name}","releases_url":"https://api.github.com/repos/Yoast/wordpress-seo/releases{/id}","deployments_url":"https://api.github.com/repos/Yoast/wordpress-seo/deployments","created_at":"2012-11-16T15:16:29Z","updated_at":"2018-05-29T11:38:37Z","pushed_at":"2018-05-29T13:36:54Z","git_url":"git://github.com/Yoast/wordpress-seo.git","ssh_url":"git@github.com:Yoast/wordpress-seo.git","clone_url":"https://github.com/Yoast/wordpress-seo.git","svn_url":"https://github.com/Yoast/wordpress-seo","homepage":"http://yoast.com/wordpress/seo/","size":259340,"stargazers_count":890,"watchers_count":890,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":525,"mirror_url":null,"archived":false,"open_issues_count":1047,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":525,"open_issues":1047,"watchers":890,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715"},"html":{"href":"https://github.com/Yoast/wordpress-seo/pull/9715"},"issue":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/issues/9715"},"comments":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/issues/9715/comments"},"review_comments":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715/comments"},"review_comment":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/pulls/9715/commits"},"statuses":{"href":"https://api.github.com/repos/Yoast/wordpress-seo/statuses/85c49873301fad41ddc608a9a9355bccc9006f1d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"andizer"}}