{"action":"created","comment":{"url":"https://api.github.com/repos/Automattic/camptix/pulls/comments/90145235","pull_request_review_id":10669152,"id":90145235,"diff_hunk":"@@ -59,179 +77,280 @@ function shutdown() {\n \t}\n \n \t/**\n-\t * Callback for the [camptix_attendees] shortcode.\n+\t * Routine to preemptively cache the content for all of a site's instances of\n+     * the [camptix_attendees] shortcode.\n \t */\n-\tfunction shortcode_attendees( $attr ) {\n-\t\tglobal $post, $camptix;\n-\n-\t\t$attr = shortcode_atts( array(\n-\t\t\t'order' => 'ASC',\n-\t\t\t'orderby' => 'title',\n-\t\t\t'posts_per_page' => 10000,\n-\t\t\t'tickets' => false,\n-\t\t\t'columns' => 3,\n-\t\t\t'questions' => '',\n-\t\t), $attr, 'camptix_attendees' );\n-\n-\t\t$camptix_options = $camptix->get_options();\n+\tpublic function cache_all_attendees_shortcodes() {\n+        // Get posts containing the `camptix_attendees` shortcode\n+\t\t$params = array(\n+\t\t\t'post_type'              => 'page',\n+\t\t\t'post_status'            => 'publish',\n+\t\t\t's'                      => '[camptix_attendees',\n+\t\t\t'posts_per_page'         => 50,\n+\t\t\t'update_post_term_cache' => false,\n+\t\t\t'update_post_meta_cache' => false,\n+\t\t);\n+\t\t$posts  = get_posts( $params );\n \n-\t\t// Enqueue Jetpack's spinner script if available\n-\t\tif ( wp_script_is( 'jquery.spin', 'registered' ) ) {\n-\t\t\twp_enqueue_script( 'jquery.spin' );\n+\t\tif ( ! $posts ) {\n+\t\t\treturn;\n \t\t}\n \n-\t\t// For wp.template()\n-\t\twp_enqueue_script( 'wp-util' );\n+\t\t$regex = get_shortcode_regex( array( 'camptix_attendees' ) );\n \n-\t\t// Lazy load the camptix js.\n+\t\tforeach ( $posts as $post ) {\n+\t\t\t$matches = array();\n+\n+\t\t\tif ( ! preg_match_all( $regex, $post->post_content, $matches, PREG_SET_ORDER ) ) {\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tforeach ( $matches as $match ) {\n+\t\t\t\t$attr = shortcode_parse_atts( $match[3] );\n+\t\t\t\t$attr = $this->sanitize_attendees_atts( $attr );\n+\n+                $this->get_attendees_shortcode_content( $attr );\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Callback for the [camptix_attendees] shortcode.\n+\t */\n+\tpublic function shortcode_attendees( $attr ) {\n+\t\t// Required scripts\n+\t\twp_enqueue_script( 'wp-util' ); // For wp.template()\n+\t\tif ( wp_script_is( 'jquery.spin', 'registered' ) ) {\n+\t\t\twp_enqueue_script( 'jquery.spin' ); // Enqueue Jetpack's spinner script if available\n+\t\t}\n \t\twp_enqueue_script( 'camptix' );\n \n \t\t// Only print the JS template once.\n \t\tif ( ! has_action( 'wp_print_footer_scripts', array( $this, 'avatar_js_template' ) ) ) {\n \t\t\tadd_action( 'wp_print_footer_scripts', array( $this, 'avatar_js_template' ) );\n \t\t}\n \n-\t\t$start = microtime(true);\n+\t\t$attr = $this->sanitize_attendees_atts( $attr );\n+\n+\t\t/**\n+\t\t *\n+\t\t */\n+\t\tdo_action( 'camptix_attendees_shortcode_init', $attr );\n+\n+\t\treturn $this->get_attendees_shortcode_content( $attr );\n+\t}\n+\n+\t/**\n+\t * Generate the key for a particular configuration to use when\n+\t * setting or retrieving a cached value.\n+\t *\n+\t * @param array $attr    Sanitized shortcode attributes\n+\t *\n+\t * @return string        The cache key\n+\t */\n+\tprotected function generate_attendees_cache_key( $attr ) {\n+\t\treturn 'camptix-attendees-' . md5( maybe_serialize( $attr ) );\n+\t}\n+\n+\t/**\n+\t * Get the content for an instance of the [camptix_attendees] shortcode.\n+\t *\n+\t * This checks for a cached version first. If none is found, it generates\n+\t * the content and caches it before returning.\n+\t *\n+\t * @param array $attr             Sanitized shortcode attributes\n+\t * @param bool  $force_refresh    True to generate the content even if cached value is found.\n+\t *\n+\t * @return string                 Rendered shortcode content\n+\t */\n+\tpublic function get_attendees_shortcode_content( $attr, $force_refresh = false ) {\n+\t\tglobal $camptix;\n+\n+\t\t// Cache duration. Day for active sites, month for archived sites.\n+\t\t$camptix_options = $camptix->get_options();\n+\t\t$cache_time = ( $camptix_options['archived'] ) ? DAY_IN_SECONDS * 30 : DAY_IN_SECONDS;\n \n-\t\t// Serve from cache if cached copy is fresh.\n-\t\t$transient_key = md5( 'tix-attendees' . serialize( $attr ) );\n-\t\tif ( false !== ( $cached = get_transient( $transient_key ) ) ) {\n-\t\t\tif ( ! is_array( $cached ) )\n-\t\t\t\treturn $cached; // back-compat\n+\t\t$cache_key = $this->generate_attendees_cache_key( $attr );\n \n-\t\t\t// Compare the cached time to the last modified time from stats.\n-\t\t\telseif ( $cached['time'] > $camptix->get_stats( 'last_modified' ) )\n+\t\t// Return the cached value if nothing has changed since it was generated\n+\t\tif ( ! $force_refresh && false !== ( $cached = get_transient( $cache_key ) ) ) {\n+\t\t\tif ( $cached['time'] > $camptix->get_stats( 'last_modified' ) ) {","path":"addons/shortcodes.php","position":null,"original_position":169,"commit_id":"af5c4d1f62106dc88251110ffafd288c38130383","original_commit_id":"8d32c6a1ddfb28b67ee0e7d7149291902539b89e","user":{"login":"coreymckrill","id":916023,"avatar_url":"https://avatars.githubusercontent.com/u/916023?v=3","gravatar_id":"","url":"https://api.github.com/users/coreymckrill","html_url":"https://github.com/coreymckrill","followers_url":"https://api.github.com/users/coreymckrill/followers","following_url":"https://api.github.com/users/coreymckrill/following{/other_user}","gists_url":"https://api.github.com/users/coreymckrill/gists{/gist_id}","starred_url":"https://api.github.com/users/coreymckrill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreymckrill/subscriptions","organizations_url":"https://api.github.com/users/coreymckrill/orgs","repos_url":"https://api.github.com/users/coreymckrill/repos","events_url":"https://api.github.com/users/coreymckrill/events{/privacy}","received_events_url":"https://api.github.com/users/coreymckrill/received_events","type":"User","site_admin":false},"body":"@iandunn I've addressed this with 08a4c1c","created_at":"2016-11-30T00:18:23Z","updated_at":"2016-11-30T00:18:23Z","html_url":"https://github.com/Automattic/camptix/pull/158#discussion_r90145235","pull_request_url":"https://api.github.com/repos/Automattic/camptix/pulls/158","_links":{"self":{"href":"https://api.github.com/repos/Automattic/camptix/pulls/comments/90145235"},"html":{"href":"https://github.com/Automattic/camptix/pull/158#discussion_r90145235"},"pull_request":{"href":"https://api.github.com/repos/Automattic/camptix/pulls/158"}}},"pull_request":{"url":"https://api.github.com/repos/Automattic/camptix/pulls/158","id":95772257,"html_url":"https://github.com/Automattic/camptix/pull/158","diff_url":"https://github.com/Automattic/camptix/pull/158.diff","patch_url":"https://github.com/Automattic/camptix/pull/158.patch","issue_url":"https://api.github.com/repos/Automattic/camptix/issues/158","number":158,"state":"open","locked":false,"title":"Attendees shortcode: Refactor caching of attendees lists","user":{"login":"coreymckrill","id":916023,"avatar_url":"https://avatars.githubusercontent.com/u/916023?v=3","gravatar_id":"","url":"https://api.github.com/users/coreymckrill","html_url":"https://github.com/coreymckrill","followers_url":"https://api.github.com/users/coreymckrill/followers","following_url":"https://api.github.com/users/coreymckrill/following{/other_user}","gists_url":"https://api.github.com/users/coreymckrill/gists{/gist_id}","starred_url":"https://api.github.com/users/coreymckrill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreymckrill/subscriptions","organizations_url":"https://api.github.com/users/coreymckrill/orgs","repos_url":"https://api.github.com/users/coreymckrill/repos","events_url":"https://api.github.com/users/coreymckrill/events{/privacy}","received_events_url":"https://api.github.com/users/coreymckrill/received_events","type":"User","site_admin":false},"body":"This refactors the way that the shortcode content is generated, splitting the functionality into several smaller methods so that the content can be generated and cached in a separate cronjob as well as when the shortcode callback is fired.\r\n\r\nThis attempts to mitigate the issue of a potentially long, slow page load if a large attendees list is requested and no cached version is available.\r\n\r\ncc @iandunn ","created_at":"2016-11-29T20:48:01Z","updated_at":"2016-11-30T00:18:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d247b91451b5117e7d1909287e7f169ef79393cc","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Automattic/camptix/pulls/158/commits","review_comments_url":"https://api.github.com/repos/Automattic/camptix/pulls/158/comments","review_comment_url":"https://api.github.com/repos/Automattic/camptix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Automattic/camptix/issues/158/comments","statuses_url":"https://api.github.com/repos/Automattic/camptix/statuses/af5c4d1f62106dc88251110ffafd288c38130383","head":{"label":"Automattic:cache-attendees","ref":"cache-attendees","sha":"af5c4d1f62106dc88251110ffafd288c38130383","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":5188983,"name":"camptix","full_name":"Automattic/camptix","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/camptix","description":"Simple and Flexible WordPress ticketing plugin brought to you by WordCamp.org","fork":false,"url":"https://api.github.com/repos/Automattic/camptix","forks_url":"https://api.github.com/repos/Automattic/camptix/forks","keys_url":"https://api.github.com/repos/Automattic/camptix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/camptix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/camptix/teams","hooks_url":"https://api.github.com/repos/Automattic/camptix/hooks","issue_events_url":"https://api.github.com/repos/Automattic/camptix/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/camptix/events","assignees_url":"https://api.github.com/repos/Automattic/camptix/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/camptix/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/camptix/tags","blobs_url":"https://api.github.com/repos/Automattic/camptix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/camptix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/camptix/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/camptix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/camptix/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/camptix/languages","stargazers_url":"https://api.github.com/repos/Automattic/camptix/stargazers","contributors_url":"https://api.github.com/repos/Automattic/camptix/contributors","subscribers_url":"https://api.github.com/repos/Automattic/camptix/subscribers","subscription_url":"https://api.github.com/repos/Automattic/camptix/subscription","commits_url":"https://api.github.com/repos/Automattic/camptix/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/camptix/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/camptix/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/camptix/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/camptix/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/camptix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/camptix/merges","archive_url":"https://api.github.com/repos/Automattic/camptix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/camptix/downloads","issues_url":"https://api.github.com/repos/Automattic/camptix/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/camptix/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/camptix/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/camptix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/camptix/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/camptix/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/camptix/deployments","created_at":"2012-07-26T07:14:14Z","updated_at":"2016-10-30T15:36:25Z","pushed_at":"2016-11-30T00:16:20Z","git_url":"git://github.com/Automattic/camptix.git","ssh_url":"git@github.com:Automattic/camptix.git","clone_url":"https://github.com/Automattic/camptix.git","svn_url":"https://github.com/Automattic/camptix","homepage":"","size":3166,"stargazers_count":155,"watchers_count":155,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":61,"mirror_url":null,"open_issues_count":36,"forks":61,"open_issues":36,"watchers":155,"default_branch":"master"}},"base":{"label":"Automattic:master","ref":"master","sha":"b706feaef6354436b60874a113de4aaa71cf880e","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":5188983,"name":"camptix","full_name":"Automattic/camptix","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/camptix","description":"Simple and Flexible WordPress ticketing plugin brought to you by WordCamp.org","fork":false,"url":"https://api.github.com/repos/Automattic/camptix","forks_url":"https://api.github.com/repos/Automattic/camptix/forks","keys_url":"https://api.github.com/repos/Automattic/camptix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/camptix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/camptix/teams","hooks_url":"https://api.github.com/repos/Automattic/camptix/hooks","issue_events_url":"https://api.github.com/repos/Automattic/camptix/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/camptix/events","assignees_url":"https://api.github.com/repos/Automattic/camptix/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/camptix/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/camptix/tags","blobs_url":"https://api.github.com/repos/Automattic/camptix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/camptix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/camptix/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/camptix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/camptix/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/camptix/languages","stargazers_url":"https://api.github.com/repos/Automattic/camptix/stargazers","contributors_url":"https://api.github.com/repos/Automattic/camptix/contributors","subscribers_url":"https://api.github.com/repos/Automattic/camptix/subscribers","subscription_url":"https://api.github.com/repos/Automattic/camptix/subscription","commits_url":"https://api.github.com/repos/Automattic/camptix/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/camptix/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/camptix/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/camptix/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/camptix/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/camptix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/camptix/merges","archive_url":"https://api.github.com/repos/Automattic/camptix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/camptix/downloads","issues_url":"https://api.github.com/repos/Automattic/camptix/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/camptix/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/camptix/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/camptix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/camptix/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/camptix/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/camptix/deployments","created_at":"2012-07-26T07:14:14Z","updated_at":"2016-10-30T15:36:25Z","pushed_at":"2016-11-30T00:16:20Z","git_url":"git://github.com/Automattic/camptix.git","ssh_url":"git@github.com:Automattic/camptix.git","clone_url":"https://github.com/Automattic/camptix.git","svn_url":"https://github.com/Automattic/camptix","homepage":"","size":3166,"stargazers_count":155,"watchers_count":155,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":61,"mirror_url":null,"open_issues_count":36,"forks":61,"open_issues":36,"watchers":155,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Automattic/camptix/pulls/158"},"html":{"href":"https://github.com/Automattic/camptix/pull/158"},"issue":{"href":"https://api.github.com/repos/Automattic/camptix/issues/158"},"comments":{"href":"https://api.github.com/repos/Automattic/camptix/issues/158/comments"},"review_comments":{"href":"https://api.github.com/repos/Automattic/camptix/pulls/158/comments"},"review_comment":{"href":"https://api.github.com/repos/Automattic/camptix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Automattic/camptix/pulls/158/commits"},"statuses":{"href":"https://api.github.com/repos/Automattic/camptix/statuses/af5c4d1f62106dc88251110ffafd288c38130383"}}}}
{"actor":{"display_login":"coreymckrill"}}