From 03eaa7230dbc056a7a03b16e52aa363a2af0a722 Mon Sep 17 00:00:00 2001 From: Chris Abraham Date: Mon, 18 Nov 2024 13:13:33 -0800 Subject: [PATCH 1/4] Quadruple the number of people for stress testing Signed-off-by: Chris Abraham --- .../lf-mu/admin/partials/cpts.php | 2 +- .../lf-mu/admin/partials/sync-people.php | 223 +++++++++--------- 2 files changed, 113 insertions(+), 112 deletions(-) diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/cpts.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/cpts.php index d1512a22b..9ddc27f34 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/cpts.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/cpts.php @@ -180,7 +180,7 @@ 'singular_name' => __( 'Person' ), 'all_items' => __( 'All People' ), ), - 'public' => false, + 'public' => true, 'has_archive' => false, 'show_in_nav_menus' => false, 'show_in_rest' => true, diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php index 563f13500..8afe526db 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php @@ -77,129 +77,130 @@ function geocode_location( $id ) { $synced_ids = array(); foreach ( $people as $p ) { - - $params = array( - 'post_type' => 'lf_person', - 'post_title' => $p->name, - 'post_content' => $p->bio, - 'post_status' => 'publish', - 'meta_input' => array(), - ); - - if ( property_exists( $p, 'company' ) ) { - $params['meta_input']['lf_person_company'] = $p->company; - } - if ( property_exists( $p, 'company_logo_url' ) ) { - $params['meta_input']['lf_person_company_logo_url'] = $p->company_logo_url; - } - if ( property_exists( $p, 'company_landscape_url' ) ) { - $params['meta_input']['lf_person_company_landscape_url'] = $p->company_landscape_url; - } - if ( property_exists( $p, 'pronouns' ) ) { - $params['meta_input']['lf_person_pronouns'] = $p->pronouns; - } - if ( property_exists( $p, 'location' ) ) { - $params['meta_input']['lf_person_location'] = $p->location; - } - if ( property_exists( $p, 'toc_role' ) ) { - $params['meta_input']['lf_person_toc_role'] = $p->toc_role; - } - if ( property_exists( $p, 'gb_role' ) ) { - $params['meta_input']['lf_person_gb_role'] = $p->gb_role; - } - if ( property_exists( $p, 'tab_role' ) ) { - $params['meta_input']['lf_person_tab_role'] = $p->tab_role; - } - if ( property_exists( $p, 'linkedin' ) ) { - $params['meta_input']['lf_person_linkedin'] = $p->linkedin; - } - if ( property_exists( $p, 'bluesky' ) ) { - $params['meta_input']['lf_person_bluesky'] = $p->bluesky; - } - if ( property_exists( $p, 'twitter' ) ) { - $params['meta_input']['lf_person_twitter'] = $p->twitter; - } - if ( property_exists( $p, 'mastodon' ) ) { - $params['meta_input']['lf_person_mastodon'] = $p->mastodon; - } - if ( property_exists( $p, 'github' ) ) { - $params['meta_input']['lf_person_github'] = $p->github; - } - if ( property_exists( $p, 'wechat' ) ) { - $params['meta_input']['lf_person_wechat'] = $p->wechat; - } - if ( property_exists( $p, 'youtube' ) ) { - $params['meta_input']['lf_person_youtube'] = $p->youtube; - } - if ( property_exists( $p, 'priority' ) ) { - $params['meta_input']['lf_person_is_priority'] = $p->priority; - } else { - $params['meta_input']['lf_person_is_priority'] = 0; - } - if ( property_exists( $p, 'image' ) ) { - if ( strpos( $p->image, 'http' ) !== false ) { - $image_url = $p->image; + for ( $i = 0; $i < 3; $i++ ) { + $params = array( + 'post_type' => 'lf_person', + 'post_title' => $p->name . $i, + 'post_content' => $p->bio, + 'post_status' => 'publish', + 'meta_input' => array(), + ); + + if ( property_exists( $p, 'company' ) ) { + $params['meta_input']['lf_person_company'] = $p->company; + } + if ( property_exists( $p, 'company_logo_url' ) ) { + $params['meta_input']['lf_person_company_logo_url'] = $p->company_logo_url; + } + if ( property_exists( $p, 'company_landscape_url' ) ) { + $params['meta_input']['lf_person_company_landscape_url'] = $p->company_landscape_url; + } + if ( property_exists( $p, 'pronouns' ) ) { + $params['meta_input']['lf_person_pronouns'] = $p->pronouns; + } + if ( property_exists( $p, 'location' ) ) { + $params['meta_input']['lf_person_location'] = $p->location; + } + if ( property_exists( $p, 'toc_role' ) ) { + $params['meta_input']['lf_person_toc_role'] = $p->toc_role; + } + if ( property_exists( $p, 'gb_role' ) ) { + $params['meta_input']['lf_person_gb_role'] = $p->gb_role; + } + if ( property_exists( $p, 'tab_role' ) ) { + $params['meta_input']['lf_person_tab_role'] = $p->tab_role; + } + if ( property_exists( $p, 'linkedin' ) ) { + $params['meta_input']['lf_person_linkedin'] = $p->linkedin; + } + if ( property_exists( $p, 'bluesky' ) ) { + $params['meta_input']['lf_person_bluesky'] = $p->bluesky; + } + if ( property_exists( $p, 'twitter' ) ) { + $params['meta_input']['lf_person_twitter'] = $p->twitter; + } + if ( property_exists( $p, 'mastodon' ) ) { + $params['meta_input']['lf_person_mastodon'] = $p->mastodon; + } + if ( property_exists( $p, 'github' ) ) { + $params['meta_input']['lf_person_github'] = $p->github; + } + if ( property_exists( $p, 'wechat' ) ) { + $params['meta_input']['lf_person_wechat'] = $p->wechat; + } + if ( property_exists( $p, 'youtube' ) ) { + $params['meta_input']['lf_person_youtube'] = $p->youtube; + } + if ( property_exists( $p, 'priority' ) ) { + $params['meta_input']['lf_person_is_priority'] = $p->priority; } else { - $image_url = $github_images_url . $p->image; + $params['meta_input']['lf_person_is_priority'] = 0; + } + if ( property_exists( $p, 'image' ) ) { + if ( strpos( $p->image, 'http' ) !== false ) { + $image_url = $p->image; + } else { + $image_url = $github_images_url . $p->image; + } + $params['meta_input']['lf_person_image'] = $image_url; + } + if ( property_exists( $p, 'website' ) ) { + $params['meta_input']['lf_person_website'] = $p->website; } - $params['meta_input']['lf_person_image'] = $image_url; - } - if ( property_exists( $p, 'website' ) ) { - $params['meta_input']['lf_person_website'] = $p->website; - } - $args = array( - 'post_type' => 'lf_person', - 'title' => $p->name, - 'post_status' => 'publish', - 'numberposts' => 1, - ); + $args = array( + 'post_type' => 'lf_person', + 'title' => $p->name . $i, + 'post_status' => 'publish', + 'numberposts' => 1, + ); - if ( $image_url ) { - $args['meta_value'] = $image_url; - } + if ( $image_url ) { + $args['meta_value'] = $image_url; + } - $pp = get_posts( $args ); + $pp = get_posts( $args ); - if ( ! empty( $pp ) ) { - $params['ID'] = $pp[0]->ID; - } + if ( ! empty( $pp ) ) { + $params['ID'] = $pp[0]->ID; + } - $newid = wp_insert_post( $params ); // will insert or update the post as needed. + $newid = wp_insert_post( $params ); // will insert or update the post as needed. - if ( $newid ) { - if ( property_exists( $p, 'languages' ) ) { - wp_set_object_terms( $newid, $p->languages, 'lf-language', false ); - } - if ( property_exists( $p, 'expertise' ) ) { - wp_set_object_terms( $newid, $p->expertise, 'lf-expertise', false ); - } - $projects_to_add = array(); - if ( property_exists( $p, 'projects' ) ) { - foreach ( $p->projects as $proj ) { - if ( term_exists( $proj, 'lf-project' ) ) { - // Don't allow any non-CNCF projects to be added. - $projects_to_add[] = $proj; + if ( $newid ) { + if ( property_exists( $p, 'languages' ) ) { + wp_set_object_terms( $newid, $p->languages, 'lf-language', false ); + } + if ( property_exists( $p, 'expertise' ) ) { + wp_set_object_terms( $newid, $p->expertise, 'lf-expertise', false ); + } + $projects_to_add = array(); + if ( property_exists( $p, 'projects' ) ) { + foreach ( $p->projects as $proj ) { + if ( term_exists( $proj, 'lf-project' ) ) { + // Don't allow any non-CNCF projects to be added. + $projects_to_add[] = $proj; + } } + wp_set_object_terms( $newid, $projects_to_add, 'lf-project', false ); } - wp_set_object_terms( $newid, $projects_to_add, 'lf-project', false ); - } - if ( property_exists( $p, 'category' ) ) { - wp_set_object_terms( $newid, $p->category, 'lf-person-category', false ); - } else { - wp_set_object_terms( $newid, array(), 'lf-person-category', false ); - } - if ( property_exists( $p, 'location' ) ) { - $country_arr = explode( ',', $params['meta_input']['lf_person_location'] ); - $country = trim( end( $country_arr ) ); - $term_exists = term_exists( $country, 'lf-country' ); - if ( $term_exists ) { - wp_set_object_terms( $newid, (int) $term_exists['term_id'], 'lf-country', false ); + if ( property_exists( $p, 'category' ) ) { + wp_set_object_terms( $newid, $p->category, 'lf-person-category', false ); + } else { + wp_set_object_terms( $newid, array(), 'lf-person-category', false ); + } + if ( property_exists( $p, 'location' ) ) { + $country_arr = explode( ',', $params['meta_input']['lf_person_location'] ); + $country = trim( end( $country_arr ) ); + $term_exists = term_exists( $country, 'lf-country' ); + if ( $term_exists ) { + wp_set_object_terms( $newid, (int) $term_exists['term_id'], 'lf-country', false ); + } + geocode_location( $newid ); } - geocode_location( $newid ); - } - $synced_ids[] = $newid; + $synced_ids[] = $newid; + } } } From 111aa1b1f483678f39fd6696518277a4ccaa49ff Mon Sep 17 00:00:00 2001 From: Chris Abraham Date: Mon, 18 Nov 2024 13:26:53 -0800 Subject: [PATCH 2/4] sync people on refresh temporarily Signed-off-by: Chris Abraham --- .../mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php index 3ab5d34f8..c972640de 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php @@ -205,7 +205,7 @@ private function define_admin_hooks() { // Example of how to run a sync locally on demand. // $this->loader->add_action( 'init', $plugin_admin, 'sync_kcds' ); //phpcs:ignore. - // $this->loader->add_action( 'init', $plugin_admin, 'sync_people' ); //phpcs:ignore. + $this->loader->add_action( 'init', $plugin_admin, 'sync_people' ); //phpcs:ignore. $this->loader->add_filter( 'dashboard_glance_items', $plugin_admin, 'custom_glance_items', 10, 1 ); From a90908c4bf4187786a470839aabfdb809ebb4152 Mon Sep 17 00:00:00 2001 From: Chris Abraham Date: Mon, 18 Nov 2024 13:41:54 -0800 Subject: [PATCH 3/4] turn off people sync on refresh Signed-off-by: Chris Abraham --- .../mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php index c972640de..3ab5d34f8 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php @@ -205,7 +205,7 @@ private function define_admin_hooks() { // Example of how to run a sync locally on demand. // $this->loader->add_action( 'init', $plugin_admin, 'sync_kcds' ); //phpcs:ignore. - $this->loader->add_action( 'init', $plugin_admin, 'sync_people' ); //phpcs:ignore. + // $this->loader->add_action( 'init', $plugin_admin, 'sync_people' ); //phpcs:ignore. $this->loader->add_filter( 'dashboard_glance_items', $plugin_admin, 'custom_glance_items', 10, 1 ); From 1414639ef21f798c7ce54c276a0c69a2d6b2359c Mon Sep 17 00:00:00 2001 From: Chris Abraham Date: Tue, 19 Nov 2024 14:41:22 -0800 Subject: [PATCH 4/4] import duplicates in a deliberate way Signed-off-by: Chris Abraham --- .../lf-mu/admin/partials/sync-people.php | 245 +++++++++--------- 1 file changed, 122 insertions(+), 123 deletions(-) diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php index 8afe526db..6d0011e7c 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-people.php @@ -76,146 +76,145 @@ function geocode_location( $id ) { $synced_ids = array(); +$i = 1; foreach ( $people as $p ) { - for ( $i = 0; $i < 3; $i++ ) { - $params = array( - 'post_type' => 'lf_person', - 'post_title' => $p->name . $i, - 'post_content' => $p->bio, - 'post_status' => 'publish', - 'meta_input' => array(), - ); - - if ( property_exists( $p, 'company' ) ) { - $params['meta_input']['lf_person_company'] = $p->company; - } - if ( property_exists( $p, 'company_logo_url' ) ) { - $params['meta_input']['lf_person_company_logo_url'] = $p->company_logo_url; - } - if ( property_exists( $p, 'company_landscape_url' ) ) { - $params['meta_input']['lf_person_company_landscape_url'] = $p->company_landscape_url; - } - if ( property_exists( $p, 'pronouns' ) ) { - $params['meta_input']['lf_person_pronouns'] = $p->pronouns; - } - if ( property_exists( $p, 'location' ) ) { - $params['meta_input']['lf_person_location'] = $p->location; - } - if ( property_exists( $p, 'toc_role' ) ) { - $params['meta_input']['lf_person_toc_role'] = $p->toc_role; - } - if ( property_exists( $p, 'gb_role' ) ) { - $params['meta_input']['lf_person_gb_role'] = $p->gb_role; - } - if ( property_exists( $p, 'tab_role' ) ) { - $params['meta_input']['lf_person_tab_role'] = $p->tab_role; - } - if ( property_exists( $p, 'linkedin' ) ) { - $params['meta_input']['lf_person_linkedin'] = $p->linkedin; - } - if ( property_exists( $p, 'bluesky' ) ) { - $params['meta_input']['lf_person_bluesky'] = $p->bluesky; - } - if ( property_exists( $p, 'twitter' ) ) { - $params['meta_input']['lf_person_twitter'] = $p->twitter; - } - if ( property_exists( $p, 'mastodon' ) ) { - $params['meta_input']['lf_person_mastodon'] = $p->mastodon; - } - if ( property_exists( $p, 'github' ) ) { - $params['meta_input']['lf_person_github'] = $p->github; - } - if ( property_exists( $p, 'wechat' ) ) { - $params['meta_input']['lf_person_wechat'] = $p->wechat; - } - if ( property_exists( $p, 'youtube' ) ) { - $params['meta_input']['lf_person_youtube'] = $p->youtube; - } - if ( property_exists( $p, 'priority' ) ) { - $params['meta_input']['lf_person_is_priority'] = $p->priority; + $params = array( + 'post_type' => 'lf_person', + 'post_title' => $p->name . $i, + 'post_content' => $p->bio, + 'post_status' => 'publish', + 'meta_input' => array(), + ); + + if ( property_exists( $p, 'company' ) ) { + $params['meta_input']['lf_person_company'] = $p->company; + } + if ( property_exists( $p, 'company_logo_url' ) ) { + $params['meta_input']['lf_person_company_logo_url'] = $p->company_logo_url; + } + if ( property_exists( $p, 'company_landscape_url' ) ) { + $params['meta_input']['lf_person_company_landscape_url'] = $p->company_landscape_url; + } + if ( property_exists( $p, 'pronouns' ) ) { + $params['meta_input']['lf_person_pronouns'] = $p->pronouns; + } + if ( property_exists( $p, 'location' ) ) { + $params['meta_input']['lf_person_location'] = $p->location; + } + if ( property_exists( $p, 'toc_role' ) ) { + $params['meta_input']['lf_person_toc_role'] = $p->toc_role; + } + if ( property_exists( $p, 'gb_role' ) ) { + $params['meta_input']['lf_person_gb_role'] = $p->gb_role; + } + if ( property_exists( $p, 'tab_role' ) ) { + $params['meta_input']['lf_person_tab_role'] = $p->tab_role; + } + if ( property_exists( $p, 'linkedin' ) ) { + $params['meta_input']['lf_person_linkedin'] = $p->linkedin; + } + if ( property_exists( $p, 'bluesky' ) ) { + $params['meta_input']['lf_person_bluesky'] = $p->bluesky; + } + if ( property_exists( $p, 'twitter' ) ) { + $params['meta_input']['lf_person_twitter'] = $p->twitter; + } + if ( property_exists( $p, 'mastodon' ) ) { + $params['meta_input']['lf_person_mastodon'] = $p->mastodon; + } + if ( property_exists( $p, 'github' ) ) { + $params['meta_input']['lf_person_github'] = $p->github; + } + if ( property_exists( $p, 'wechat' ) ) { + $params['meta_input']['lf_person_wechat'] = $p->wechat; + } + if ( property_exists( $p, 'youtube' ) ) { + $params['meta_input']['lf_person_youtube'] = $p->youtube; + } + if ( property_exists( $p, 'priority' ) ) { + $params['meta_input']['lf_person_is_priority'] = $p->priority; + } else { + $params['meta_input']['lf_person_is_priority'] = 0; + } + if ( property_exists( $p, 'image' ) ) { + if ( strpos( $p->image, 'http' ) !== false ) { + $image_url = $p->image; } else { - $params['meta_input']['lf_person_is_priority'] = 0; - } - if ( property_exists( $p, 'image' ) ) { - if ( strpos( $p->image, 'http' ) !== false ) { - $image_url = $p->image; - } else { - $image_url = $github_images_url . $p->image; - } - $params['meta_input']['lf_person_image'] = $image_url; - } - if ( property_exists( $p, 'website' ) ) { - $params['meta_input']['lf_person_website'] = $p->website; + $image_url = $github_images_url . $p->image; } + $params['meta_input']['lf_person_image'] = $image_url; + } + if ( property_exists( $p, 'website' ) ) { + $params['meta_input']['lf_person_website'] = $p->website; + } - $args = array( - 'post_type' => 'lf_person', - 'title' => $p->name . $i, - 'post_status' => 'publish', - 'numberposts' => 1, - ); + $args = array( + 'post_type' => 'lf_person', + 'title' => $p->name . $i, + 'post_status' => 'publish', + 'numberposts' => 1, + ); - if ( $image_url ) { - $args['meta_value'] = $image_url; - } + if ( $image_url ) { + $args['meta_value'] = $image_url; + } - $pp = get_posts( $args ); + $pp = get_posts( $args ); - if ( ! empty( $pp ) ) { - $params['ID'] = $pp[0]->ID; - } + if ( ! empty( $pp ) ) { + $params['ID'] = $pp[0]->ID; + } - $newid = wp_insert_post( $params ); // will insert or update the post as needed. + $newid = wp_insert_post( $params ); // will insert or update the post as needed. - if ( $newid ) { - if ( property_exists( $p, 'languages' ) ) { - wp_set_object_terms( $newid, $p->languages, 'lf-language', false ); - } - if ( property_exists( $p, 'expertise' ) ) { - wp_set_object_terms( $newid, $p->expertise, 'lf-expertise', false ); - } - $projects_to_add = array(); - if ( property_exists( $p, 'projects' ) ) { - foreach ( $p->projects as $proj ) { - if ( term_exists( $proj, 'lf-project' ) ) { - // Don't allow any non-CNCF projects to be added. - $projects_to_add[] = $proj; - } + if ( $newid ) { + if ( property_exists( $p, 'languages' ) ) { + wp_set_object_terms( $newid, $p->languages, 'lf-language', false ); + } + if ( property_exists( $p, 'expertise' ) ) { + wp_set_object_terms( $newid, $p->expertise, 'lf-expertise', false ); + } + $projects_to_add = array(); + if ( property_exists( $p, 'projects' ) ) { + foreach ( $p->projects as $proj ) { + if ( term_exists( $proj, 'lf-project' ) ) { + // Don't allow any non-CNCF projects to be added. + $projects_to_add[] = $proj; } - wp_set_object_terms( $newid, $projects_to_add, 'lf-project', false ); - } - if ( property_exists( $p, 'category' ) ) { - wp_set_object_terms( $newid, $p->category, 'lf-person-category', false ); - } else { - wp_set_object_terms( $newid, array(), 'lf-person-category', false ); } - if ( property_exists( $p, 'location' ) ) { - $country_arr = explode( ',', $params['meta_input']['lf_person_location'] ); - $country = trim( end( $country_arr ) ); - $term_exists = term_exists( $country, 'lf-country' ); - if ( $term_exists ) { - wp_set_object_terms( $newid, (int) $term_exists['term_id'], 'lf-country', false ); - } - geocode_location( $newid ); + wp_set_object_terms( $newid, $projects_to_add, 'lf-project', false ); + } + if ( property_exists( $p, 'category' ) ) { + wp_set_object_terms( $newid, $p->category, 'lf-person-category', false ); + } else { + wp_set_object_terms( $newid, array(), 'lf-person-category', false ); + } + if ( property_exists( $p, 'location' ) ) { + $country_arr = explode( ',', $params['meta_input']['lf_person_location'] ); + $country = trim( end( $country_arr ) ); + $term_exists = term_exists( $country, 'lf-country' ); + if ( $term_exists ) { + wp_set_object_terms( $newid, (int) $term_exists['term_id'], 'lf-country', false ); } - - $synced_ids[] = $newid; + geocode_location( $newid ); } + + $synced_ids[] = $newid; } } // delete any People posts which aren't in $synced_ids. -$query = new WP_Query( - array( - 'post_type' => 'lf_person', - 'post__not_in' => $synced_ids, - 'posts_per_page' => -1, - ) -); -while ( $query->have_posts() ) { - $query->the_post(); - wp_delete_post( get_the_id() ); -} +// $query = new WP_Query( +// array( +// 'post_type' => 'lf_person', +// 'post__not_in' => $synced_ids, +// 'posts_per_page' => -1, +// ) +// ); +// while ( $query->have_posts() ) { +// $query->the_post(); +// wp_delete_post( get_the_id() ); +// } // clear the site cache. if ( function_exists( 'pantheon_wp_clear_edge_all' ) ) {