Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop unnecessary index exists checks on _edit_lock meta updates #6021

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

sathyapulse
Copy link
Contributor

@sathyapulse sathyapulse commented Nov 29, 2024

Description

The _edit_lock meta key is not indexed, so there is no need to check if the ES index exists.
This change removes the unnecessary index exists checks to reduce the load on the ES server.

Stack trace of the index request

[
  {
    "file": "/wp/wp-content/mu-plugins/search/elasticpress/includes/classes/Elasticsearch.php",
    "line": 1029,
    "function": "remote_request",
    "class": "ElasticPress\\Elasticsearch",
    "type": "->"
  },
  {
    "file": "/wp/wp-content/mu-plugins/search/elasticpress/includes/classes/Indexable.php",
    "line": 320,
    "function": "index_exists",
    "class": "ElasticPress\\Elasticsearch",
    "type": "->"
  },
  {
    "file": "/wp/wp-content/mu-plugins/search/includes/classes/class-search.php",
    "line": 2221,
    "function": "index_exists",
    "class": "ElasticPress\\Indexable",
    "type": "->"
  },
  {
    "file": "/wp/wp-includes/class-wp-hook.php",
    "line": 324,
    "function": "do_not_sync_if_no_index",
    "class": "Automattic\\VIP\\Search\\Search",
    "type": "->"
  },
  {
    "file": "/wp/wp-includes/plugin.php",
    "line": 205,
    "function": "apply_filters",
    "class": "WP_Hook",
    "type": "->"
  },
  {
    "file": "/wp/wp-content/mu-plugins/search/elasticpress/includes/classes/SyncManager.php",
    "line": 289,
    "function": "apply_filters"
  },
  {
    "file": "/wp/wp-content/mu-plugins/search/elasticpress/includes/classes/Indexable/Post/SyncManager.php",
    "line": 151,
    "function": "kill_sync",
    "class": "ElasticPress\\SyncManager",
    "type": "->"
  },
  {
    "file": "/wp/wp-includes/class-wp-hook.php",
    "line": 324,
    "function": "action_queue_meta_sync",
    "class": "ElasticPress\\Indexable\\Post\\SyncManager",
    "type": "->"
  },
  {
    "file": "/wp/wp-includes/class-wp-hook.php",
    "line": 348,
    "function": "apply_filters",
    "class": "WP_Hook",
    "type": "->"
  },
  {
    "file": "/wp/wp-includes/plugin.php",
    "line": 517,
    "function": "do_action",
    "class": "WP_Hook",
    "type": "->"
  }
]

Changelog Description

Added

Removed

Fixed

  • Remove index exists checks for disallowed meta keys, specifically the _edit_lock key.

Changed

Pre-review checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally or in Codespaces (or has an appropriate fallback).
  • This change works and has been tested on a sandbox.
  • This change has relevant unit tests (if applicable).
  • This change uses a rollout method to ease with deployment (if applicable - especially for large scale actions that require writes).
  • This change has relevant documentation additions / updates (if applicable).
  • I've created a changelog description that aligns with the provided examples.

Pre-deploy checklist

  • VIP staff: Ensure any alerts added/updated conform to internal standards (see internal documentation).

Steps to Test

The _edit_lock meta key is not indexed, so there is no need to check if ES index exists.
This change removes the unnecessary index exists checks to reduce load on ES server.
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 5 lines in your changes missing coverage. Please review.

Project coverage is 30.55%. Comparing base (147c588) to head (7fe0523).

Files with missing lines Patch % Lines
search/includes/classes/class-search.php 58.33% 5 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #6021      +/-   ##
=============================================
+ Coverage      30.52%   30.55%   +0.03%     
- Complexity      4811     4819       +8     
=============================================
  Files            289      289              
  Lines          21175    21175              
=============================================
+ Hits            6463     6471       +8     
+ Misses         14712    14704       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rebeccahum
Copy link
Contributor

Thank you for the PR, however, we already cache the index_exists requests into an option:

if ( false !== $cached_index_exists_request ) {
$cached_index_exists_response_code = (int) wp_remote_retrieve_response_code( $cached_index_exists_request );
if ( 'index_exists' === $type && in_array( $cached_index_exists_response_code, $valid_index_exists_response_codes, true ) ) {
// Return cached index_exists option.
return $cached_index_exists_request;
. So I'm not too worried about attempting to make that request since it will always be intercepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants