{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/jetpack/issues/2059","labels_url":"https://api.github.com/repos/Automattic/jetpack/issues/2059/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/jetpack/issues/2059/comments","events_url":"https://api.github.com/repos/Automattic/jetpack/issues/2059/events","html_url":"https://github.com/Automattic/jetpack/pull/2059","id":72212560,"number":2059,"title":"Fix unnecessary calls to functions using filters in sources. ","user":{"login":"NicoleA","id":2522972,"avatar_url":"https://avatars.githubusercontent.com/u/2522972?v=3","gravatar_id":"","url":"https://api.github.com/users/NicoleA","html_url":"https://github.com/NicoleA","followers_url":"https://api.github.com/users/NicoleA/followers","following_url":"https://api.github.com/users/NicoleA/following{/other_user}","gists_url":"https://api.github.com/users/NicoleA/gists{/gist_id}","starred_url":"https://api.github.com/users/NicoleA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NicoleA/subscriptions","organizations_url":"https://api.github.com/users/NicoleA/orgs","repos_url":"https://api.github.com/users/NicoleA/repos","events_url":"https://api.github.com/users/NicoleA/events{/privacy}","received_events_url":"https://api.github.com/users/NicoleA/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Automattic/jetpack/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/Automattic/jetpack/labels/in%20progress","name":"in progress","color":"ededed"},{"url":"https://api.github.com/repos/Automattic/jetpack/labels/Sharing","name":"Sharing","color":"c7def8"},{"url":"https://api.github.com/repos/Automattic/jetpack/labels/Team%20Partnerships","name":"Team Partnerships","color":"bfe5bf"}],"state":"open","locked":false,"assignee":{"login":"georgestephanis","id":941023,"avatar_url":"https://avatars.githubusercontent.com/u/941023?v=3","gravatar_id":"","url":"https://api.github.com/users/georgestephanis","html_url":"https://github.com/georgestephanis","followers_url":"https://api.github.com/users/georgestephanis/followers","following_url":"https://api.github.com/users/georgestephanis/following{/other_user}","gists_url":"https://api.github.com/users/georgestephanis/gists{/gist_id}","starred_url":"https://api.github.com/users/georgestephanis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/georgestephanis/subscriptions","organizations_url":"https://api.github.com/users/georgestephanis/orgs","repos_url":"https://api.github.com/users/georgestephanis/repos","events_url":"https://api.github.com/users/georgestephanis/events{/privacy}","received_events_url":"https://api.github.com/users/georgestephanis/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2015-04-30T16:26:38Z","updated_at":"2015-04-30T16:53:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Automattic/jetpack/pulls/2059","html_url":"https://github.com/Automattic/jetpack/pull/2059","diff_url":"https://github.com/Automattic/jetpack/pull/2059.diff","patch_url":"https://github.com/Automattic/jetpack/pull/2059.patch"},"body":"Reference additional comments on #2046 \r\n\r\nBecause the $share_url and $share_title are only used in the \"smart\" version of the source, the calls to the get_share_url() and get_share_title() functions has been moved into the if statement. This prevents the functions from being called unnecessarily.\r\n\r\nThe reason for has become apparent in a use case where the sharing_permlink filter is used to alter the link, but requires a call to an external api to do so. Having the get_share_url() outside the if statement means that the function is called every time the button is rendered. Whereas, moving it inside the conditional ensures it is only called where necessary.\r\n\r\nBecause the use case is not using \"smart\" buttons, the function doesn't get called until the process_request() function is called after clicking the share button. This ensures that the api call is only made when an action is taken on the button.\r\n\r\nHaving filters in these two functions, get_share_url() and get_share_title(), means that we should avoid calling them unnecessarily, preventing extraneous processing and potential pitfalls such as that encountered in this use case."},"comment":{"url":"https://api.github.com/repos/Automattic/jetpack/issues/comments/97878376","html_url":"https://github.com/Automattic/jetpack/pull/2059#issuecomment-97878376","issue_url":"https://api.github.com/repos/Automattic/jetpack/issues/2059","id":97878376,"user":{"login":"NicoleA","id":2522972,"avatar_url":"https://avatars.githubusercontent.com/u/2522972?v=3","gravatar_id":"","url":"https://api.github.com/users/NicoleA","html_url":"https://github.com/NicoleA","followers_url":"https://api.github.com/users/NicoleA/followers","following_url":"https://api.github.com/users/NicoleA/following{/other_user}","gists_url":"https://api.github.com/users/NicoleA/gists{/gist_id}","starred_url":"https://api.github.com/users/NicoleA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NicoleA/subscriptions","organizations_url":"https://api.github.com/users/NicoleA/orgs","repos_url":"https://api.github.com/users/NicoleA/repos","events_url":"https://api.github.com/users/NicoleA/events{/privacy}","received_events_url":"https://api.github.com/users/NicoleA/received_events","type":"User","site_admin":false},"created_at":"2015-04-30T16:53:42Z","updated_at":"2015-04-30T16:53:42Z","body":"Understood. Thx"}}