Skip to content

Conversation

@acicovic
Copy link
Collaborator

@acicovic acicovic commented Sep 18, 2025

Description

The performance_blending_weight API parameter was hardcoded into plugin code. With this PR we're removing the related code, so the optimal performance_blending_weight value can be auto-selected by the API.

A possible alternative was to set the default value to null, and not send the parameter to the API when null. But removing was simpler and we don't currently have any UI for this code. It will be easy to restore this if we ever need it.

Closes #3696.

Summary by CodeRabbit

  • Refactor
    • Removed the “performance blending weight” parameter from Traffic Boost suggestion generation and inbound link features. Requests now rely on server defaults, with no expected change to suggestion quality or behavior.
  • Chores
    • Cleaned up unused validation and references, simplified request payloads, and updated internal type hints and comments.
  • Documentation
    • Updated inline documentation to reflect the removal of the blending weight option.
  • Tests
    • Adjusted test coverage to align with the streamlined API behavior.

@acicovic acicovic added this to the 3.20.8 milestone Sep 18, 2025
@acicovic acicovic self-assigned this Sep 18, 2025
@acicovic acicovic added the Changelog: Fixed PR to be added under the changelog's "Fixed" section label Sep 18, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 18, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • build/content-helper/dashboard-page.asset.php is excluded by !build/**
  • build/content-helper/dashboard-page.js is excluded by !build/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Removed the performance blending weight parameter across Traffic Boost layers: provider options and payloads, REST API routes and handlers, validations, and Suggestions API endpoint types/payloads. Deleted the validator class. Requests now omit performance_blending_weight and rely on server defaults. No other control flow changes.

Changes

Cohort / File(s) Summary of changes
Traffic Boost Provider (TS)
src/content-helper/dashboard-page/pages/traffic-boost/provider.ts
Removed exported TRAFFIC_BOOST_DEFAULT_PERFORMANCE_BLENDING_WEIGHT; dropped performanceBlendingWeight from generateSuggestions and generateSuggestionForPost options and payloads; updated JSDoc.
REST API: Traffic Boost
src/rest-api/content-helper/class-endpoint-traffic-boost.php
Removed performance_blending_weight param from route schemas and handlers; stopped reading/forwarding it in generate_link_suggestions and generate_placement_suggestions; minor formatting adjustments.
REST Validation
src/rest-api/content-helper/validations/class-validate-blending-weight.php
Deleted validator class Validate_Blending_Weight and its validate method.
Suggestions API: Type/Request updates
src/services/suggestions-api/endpoints/class-endpoint-suggest-headline.php, .../class-endpoint-suggest-inbound-link-positions.php, .../class-endpoint-suggest-inbound-links.php, .../class-endpoint-suggest-linked-reference.php
Removed performance_blending_weight from PHPStan type aliases; dropped output_config/payload fields injecting the weight where present; retained other options and logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Feature: Traffic Boost, Changelog: Changed

Suggested reviewers

  • alecgeatches
  • maxschmeling

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes a clear "Description" that states the change and references the issue, but it does not follow the repository's required template: the "Motivation and context" and "How has this been tested?" sections are missing and there are no testing details or environment information for reviewers to verify the change. Because the template explicitly requests motivation/context and testing information and those are important for assessing risk and correctness, the description is not compliant with repository requirements. I therefore mark this check as a failure due to incomplete template coverage and missing test documentation. Please update the PR description to include a "Motivation and context" section explaining why removing the parameter is desirable and any user-facing or backward-compatibility implications (and keep the issue link), and add a "How has this been tested?" section with concrete test steps, environment details (PHP/WordPress versions), commands or API requests used, observed results, and any unit/integration test coverage; include screenshots if applicable. If no manual or automated tests were run, state that explicitly and provide a verification plan before merge. After those sections and testing details are added the description can be re-evaluated.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Allow optimal performance_blending_weight auto-selection" concisely and accurately captures the primary change in this PR (removing the hardcoded performance_blending_weight so the API can choose an optimal value), making it clear and relevant to reviewers scanning history. It is specific, focused on the main effect, and does not include extraneous noise.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@acicovic acicovic marked this pull request as ready for review September 18, 2025 12:14
@acicovic acicovic requested a review from a team as a code owner September 18, 2025 12:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (7)
src/services/suggestions-api/endpoints/class-endpoint-suggest-inbound-links.php (1)

63-64: Clamp and cast max_items before sending to the API.

Defensively ensure an integer ≥ 1 to avoid surprising upstream behavior.

-                'max_items' => $options['max_items'] ?? 10,
+                'max_items' => max( 1, (int) ( $options['max_items'] ?? 10 ) ),
src/rest-api/content-helper/class-endpoint-traffic-boost.php (4)

93-119: Add min/max bounds to max_items REST schema.

Declare limits in the route args so invalid values are rejected early and payload sizes are bounded.

                 'max_items'          => array(
                     'type'        => 'integer',
                     'description' => __( 'The maximum number of suggestions to return.', 'wp-parsely' ),
                     'default'     => 10,
+                    'minimum'     => 1,
+                    'maximum'     => 50,
                     'required'    => false,
                 ),

131-159: Validate/sanitize string lists for placement routes.

ignore_keywords and keyword_exclusion_list accept unvalidated arrays. Add callbacks to normalize to arrays of strings.

                 'ignore_keywords'        => array(
                     'type'        => 'array',
                     'description' => __( 'The keywords to ignore.', 'wp-parsely' ),
                     'required'    => false,
+                    'sanitize_callback' => array( __CLASS__, 'sanitize_string_array' ),
+                    'validate_callback' => array( __CLASS__, 'validate_string_array' ),
                 ),
                 'keyword_exclusion_list' => array(
                     'type'        => 'array',
                     'description' => __( 'The keywords to exclude from the suggestions.', 'wp-parsely' ),
                     'required'    => false,
                     'default'     => array(),
+                    'sanitize_callback' => array( __CLASS__, 'sanitize_string_array' ),
+                    'validate_callback' => array( __CLASS__, 'validate_string_array' ),
                 ),

Add these helpers in this class (outside the shown hunk):

private static function sanitize_string_array( $value ): array {
    $arr = is_array( $value ) ? $value : array();
    return array_values( array_filter( array_map( 'sanitize_text_field', $arr ), 'strlen' ) );
}
private static function validate_string_array( $value ) {
    if ( null === $value ) {
        return true;
    }
    if ( ! is_array( $value ) ) {
        return new \WP_Error( 'parsely_invalid_param', __( 'Expected an array of strings.', 'wp-parsely' ) );
    }
    foreach ( $value as $v ) {
        if ( ! is_string( $v ) ) {
            return new \WP_Error( 'parsely_invalid_param', __( 'Expected an array of strings.', 'wp-parsely' ) );
        }
    }
    return true;
}

346-348: Normalize request options sent to Suggestions API.

Cast and de-duplicate inputs to reduce surprises downstream.

-                'max_items'          => $max_items,
-                'url_exclusion_list' => $url_exclusion_list,
+                'max_items'          => max( 1, (int) $max_items ),
+                'url_exclusion_list' => array_values( array_unique( (array) $url_exclusion_list ) ),

454-455: Sanitize and de-duplicate keyword_exclusion_list before forwarding.

Pre-cleaning helps the Suggestions API and avoids false in_array matches later.

-                'keyword_exclusion_list' => $keyword_exclusion_list,
+                'keyword_exclusion_list' => array_values(
+                    array_unique( array_map( 'sanitize_text_field', (array) $keyword_exclusion_list ) )
+                ),
src/content-helper/dashboard-page/pages/traffic-boost/provider.ts (2)

293-299: Document the removal in JSDoc with a new @SInCE entry.

Add a second @SInCE line noting the auto-selection change so downstream integrators notice the behavior shift.

  /**
   * Generates suggestions for a given post.
   *
-  * @since 3.19.0
+  * @since 3.19.0
+  * @since X.Y.Z Removed performanceBlendingWeight; server now auto-selects the optimal blending weight.
   *
   * @param {number}   postId                   The ID of the post to generate suggestions for.
   * @param {Object}   options                  The options for the suggestions.
   * @param {number}   options.maxItems         The maximum number of items to generate.
   * @param {boolean}  options.discardPrevious  Whether to discard previous suggestions.
   * @param {string[]} options.urlExclusionList The list of URLs to exclude from the suggestions.
   * @param {boolean}  options.save             Whether to save the suggestions.

Please confirm the next plugin version to replace X.Y.Z.


333-340: Mirror the JSDoc change for placement generation.

Reflect the blending-weight removal here too for consistency.

  /**
   * Generates a placement suggestion for a given post.
   *
-  * @since 3.19.0
+  * @since 3.19.0
+  * @since X.Y.Z Removed performanceBlendingWeight; server now auto-selects the optimal blending weight.
   *
   * @param {HydratedPost}     sourcePost                  The source post.
   * @param {HydratedPost}     destinationPost             The destination post.
   * @param {TrafficBoostLink} trafficBoostLink            The traffic boost link to generate a placement for.
   * @param {Object}           options                     The options for the suggestion.
   * @param {string[]}         options.ignoreKeywords      The keywords to ignore.
   * @param {boolean}          options.save                Whether to save the suggestion.
   * @param {boolean}          options.allowDuplicateLinks Whether to allow duplicate links.

Also confirm X.Y.Z.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d897c8e and 696e8b7.

⛔ Files ignored due to path filters (2)
  • build/content-helper/dashboard-page.asset.php is excluded by !build/**
  • build/content-helper/dashboard-page.js is excluded by !build/**
📒 Files selected for processing (7)
  • src/content-helper/dashboard-page/pages/traffic-boost/provider.ts (2 hunks)
  • src/rest-api/content-helper/class-endpoint-traffic-boost.php (4 hunks)
  • src/rest-api/content-helper/validations/class-validate-blending-weight.php (0 hunks)
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-headline.php (0 hunks)
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-inbound-link-positions.php (0 hunks)
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-inbound-links.php (1 hunks)
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-linked-reference.php (0 hunks)
💤 Files with no reviewable changes (4)
  • src/rest-api/content-helper/validations/class-validate-blending-weight.php
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-headline.php
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-inbound-link-positions.php
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-linked-reference.php
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{html,php}

⚙️ CodeRabbit configuration file

**/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
  • Ensure the code follows WordPress coding standards and is well-documented.
  • Confirm the code is secure and free from vulnerabilities.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."

Files:

  • src/rest-api/content-helper/class-endpoint-traffic-boost.php
  • src/services/suggestions-api/endpoints/class-endpoint-suggest-inbound-links.php
**/*.{js,ts,tsx,jsx}

⚙️ CodeRabbit configuration file

**/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."

Files:

  • src/content-helper/dashboard-page/pages/traffic-boost/provider.ts
🔇 Additional comments (1)
src/rest-api/content-helper/class-endpoint-traffic-boost.php (1)

93-119: No remaining references to performance_blending_weight found.

Scanned repository with rg/git-grep/grep and inspected src/rest-api/content-helper/class-endpoint-traffic-boost.php (lines 1–700); no matches.

@acicovic acicovic merged commit 7177001 into develop Oct 2, 2025
37 checks passed
@acicovic acicovic deleted the fix-allow-optimal-performance-blending-weight-auto-selection branch October 2, 2025 16:54
github-actions bot added a commit that referenced this pull request Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed PR to be added under the changelog's "Fixed" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let suggestions API auto-determine ideal performance blending weight

2 participants