{"action":"created","issue":{"url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/issues/976","repository_url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro","labels_url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/issues/976/labels{/name}","comments_url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/issues/976/comments","events_url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/issues/976/events","html_url":"https://github.com/restrictcontentpro/restrict-content-pro/issues/976","id":207839003,"number":976,"title":"Improve efficiency of rcp_process_gateway_webooks()","user":{"login":"mindctrl","id":1254870,"avatar_url":"https://avatars.githubusercontent.com/u/1254870?v=3","gravatar_id":"","url":"https://api.github.com/users/mindctrl","html_url":"https://github.com/mindctrl","followers_url":"https://api.github.com/users/mindctrl/followers","following_url":"https://api.github.com/users/mindctrl/following{/other_user}","gists_url":"https://api.github.com/users/mindctrl/gists{/gist_id}","starred_url":"https://api.github.com/users/mindctrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindctrl/subscriptions","organizations_url":"https://api.github.com/users/mindctrl/orgs","repos_url":"https://api.github.com/users/mindctrl/repos","events_url":"https://api.github.com/users/mindctrl/events{/privacy}","received_events_url":"https://api.github.com/users/mindctrl/received_events","type":"User","site_admin":false},"labels":[{"id":5100959,"url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/milestones/62","html_url":"https://github.com/restrictcontentpro/restrict-content-pro/milestone/62","labels_url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/milestones/62/labels","id":2218137,"number":62,"title":"2.7.4","description":null,"creator":{"login":"pippinsplugins","id":1034109,"avatar_url":"https://avatars.githubusercontent.com/u/1034109?v=3","gravatar_id":"","url":"https://api.github.com/users/pippinsplugins","html_url":"https://github.com/pippinsplugins","followers_url":"https://api.github.com/users/pippinsplugins/followers","following_url":"https://api.github.com/users/pippinsplugins/following{/other_user}","gists_url":"https://api.github.com/users/pippinsplugins/gists{/gist_id}","starred_url":"https://api.github.com/users/pippinsplugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pippinsplugins/subscriptions","organizations_url":"https://api.github.com/users/pippinsplugins/orgs","repos_url":"https://api.github.com/users/pippinsplugins/repos","events_url":"https://api.github.com/users/pippinsplugins/events{/privacy}","received_events_url":"https://api.github.com/users/pippinsplugins/received_events","type":"User","site_admin":false},"open_issues":10,"closed_issues":0,"state":"open","created_at":"2016-12-28T00:07:31Z","updated_at":"2017-02-15T17:04:17Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2017-02-15T15:38:12Z","updated_at":"2017-02-15T17:14:04Z","closed_at":null,"body":"In https://github.com/restrictcontentpro/restrict-content-pro/issues/918 we added code to ensure the webhook processing doesn't kick off during ajax, cron, and is_admin events. But it doesn't go far enough for my liking. Here's why. Using wp cli's profile tool to spotlight only the slower callbacks, here's what we get:\r\n\r\n```\r\nwp profile hook init --spotlight --fields=callback,location,time\r\n\r\nbefore\r\n+---------------------------------------+------------------------------------------------------------------+---------+\r\n| callback                              | location                                                         | time    |\r\n+---------------------------------------+------------------------------------------------------------------+---------+\r\n| rcp_process_gateway_webooks()         | restrict-content-pro/includes/gateways/gateway-functions.php:137 | 0.3672s |\r\n| create_initial_post_types()           | wp-includes/post.php:20                                          | 0.0141s |\r\n| wp_widgets_init()                     | wp-includes/widgets.php:1438                                     | 0.0191s |\r\n| edd_setup_edd_post_types()            | easy-digital-downloads/includes/post-types.php:21                | 0.0113s |\r\n| WC_Install::init_background_updater() | woocommerce/includes/class-wc-install.php:98                     | 0.0146s |\r\n| WC_Post_types::register_taxonomies()  | woocommerce/includes/class-wc-post-types.php:37                  | 0.0111s |\r\n| WC_Post_types::register_post_types()  | woocommerce/includes/class-wc-post-types.php:227                 | 0.0151s |\r\n+---------------------------------------+------------------------------------------------------------------+---------+\r\n| total (7)                             |                                                                  | 0.4525s |\r\n+---------------------------------------+------------------------------------------------------------------+---------+\r\n```\r\n\r\nIt takes a little over 1/3 of a second to run. That's considerable.\r\n\r\nOn every page load where `init` fires, every single gateway class is instantiated and the `process_webhooks()` method for each gateway runs.\r\n\r\nOne solution: we can return early in `rcp_process_gateway_webooks()` when `$_GET['listener']` isn't set, and we get this:\r\n```\r\nafter (returning early in rcp_process_gateway_webooks() if $_GET['listener'] not set, it's no longer shown because it's no longer slow)\r\n+---------------------------------------+---------------------------------------------------+---------+\r\n| callback                              | location                                          | time    |\r\n+---------------------------------------+---------------------------------------------------+---------+\r\n| create_initial_post_types()           | wp-includes/post.php:20                           | 0.0144s |\r\n| wp_widgets_init()                     | wp-includes/widgets.php:1438                      | 0.0204s |\r\n| edd_setup_edd_post_types()            | easy-digital-downloads/includes/post-types.php:21 | 0.0117s |\r\n| WC_Install::init_background_updater() | woocommerce/includes/class-wc-install.php:98      | 0.0179s |\r\n| WC_Post_types::register_taxonomies()  | woocommerce/includes/class-wc-post-types.php:37   | 0.0133s |\r\n| WC_Post_types::register_post_types()  | woocommerce/includes/class-wc-post-types.php:227  | 0.0194s |\r\n+---------------------------------------+---------------------------------------------------+---------+\r\n| total (6)                             |                                                   | 0.0972s |\r\n+---------------------------------------+---------------------------------------------------+---------+\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/issues/comments/280074466","html_url":"https://github.com/restrictcontentpro/restrict-content-pro/issues/976#issuecomment-280074466","issue_url":"https://api.github.com/repos/restrictcontentpro/restrict-content-pro/issues/976","id":280074466,"user":{"login":"pippinsplugins","id":1034109,"avatar_url":"https://avatars.githubusercontent.com/u/1034109?v=3","gravatar_id":"","url":"https://api.github.com/users/pippinsplugins","html_url":"https://github.com/pippinsplugins","followers_url":"https://api.github.com/users/pippinsplugins/followers","following_url":"https://api.github.com/users/pippinsplugins/following{/other_user}","gists_url":"https://api.github.com/users/pippinsplugins/gists{/gist_id}","starred_url":"https://api.github.com/users/pippinsplugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pippinsplugins/subscriptions","organizations_url":"https://api.github.com/users/pippinsplugins/orgs","repos_url":"https://api.github.com/users/pippinsplugins/repos","events_url":"https://api.github.com/users/pippinsplugins/events{/privacy}","received_events_url":"https://api.github.com/users/pippinsplugins/received_events","type":"User","site_admin":false},"created_at":"2017-02-15T17:14:04Z","updated_at":"2017-02-15T17:14:04Z","body":"I like that!"}}
{"actor":{"display_login":"pippinsplugins"}}