Skip to content

Fix update metadata endpoint calling issues#3092

Merged
acicovic merged 2 commits intodevelopfrom
fix/update-metadata-calling-issues
Jan 24, 2025
Merged

Fix update metadata endpoint calling issues#3092
acicovic merged 2 commits intodevelopfrom
fix/update-metadata-calling-issues

Conversation

@acicovic
Copy link
Collaborator

@acicovic acicovic commented Jan 21, 2025

Description

Our logic for calling Parse.ly's update metadata endpoint had multiple flaws. For example, the endpoint would be called for untrackable post types (e.g. revisions) and post statuses (e.g drafts).

This PR makes a bit of a cleanup and updates the function to work as expected, which is the endpoint getting called only for post types and statuses which are trackable. We're also stopping the calls from happening while integration tests are running.

Motivation and context

Eliminate needless calls to infrastructure and prevent invalid data from being posted to the endpoint.

How has this been tested?

A few integration tests were added.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved metadata endpoint handling with more robust checks and error management
    • Simplified post status tracking logic
  • Tests

    • Added comprehensive integration tests for metadata endpoint functionality
    • Enhanced test coverage for various credential and post type scenarios
  • Refactor

    • Renamed update_metadata_endpoint method to call_update_metadata_endpoint
    • Removed unnecessary caching mechanisms
  • Documentation

    • Improved method documentation and error handling comments

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

coderabbitai bot commented Jan 21, 2025

📝 Walkthrough

Walkthrough

This pull request introduces modifications to the Parse.ly WordPress plugin's core functionality, focusing on metadata endpoint handling and settings configuration. The changes primarily involve updating the Parsely class method for metadata endpoint calls, removing a filter in the settings page, and adding comprehensive integration tests to validate the new endpoint behavior. The modifications aim to improve the plugin's metadata processing and tracking capabilities.

Changes

File Change Summary
src/UI/class-settings-page.php Removed filter wp_parsely_trackable_statuses from initialize_recrawl_section() method
src/class-parsely.php - Renamed update_metadata_endpoint() to call_update_metadata_endpoint()
- Modified method to return boolean
- Added comprehensive checks before API call
- Removed post status caching in post_has_trackable_status()
tests/Integration/CallUpdateMetadataEndpointTest.php Added new integration test class to validate metadata endpoint functionality under various scenarios

Sequence Diagram

sequenceDiagram
    participant Plugin as Parsely Plugin
    participant Endpoint as Update Metadata Endpoint
    
    Plugin->>Plugin: Validate Credentials
    Plugin->>Plugin: Check Post Type
    Plugin->>Plugin: Verify Post Status
    
    alt Valid Conditions
        Plugin->>Endpoint: Call Update Metadata
        Endpoint-->>Plugin: Return Success
    else Invalid Conditions
        Plugin-->>Plugin: Return False
    end
Loading

Possibly related PRs

Suggested labels

Changelog: Changed, Type: Refactoring

Suggested reviewers

  • vaurdan

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@acicovic acicovic added the Maintenance & Fixes Ticket/PR related to codebase maintenance tasks label Jan 21, 2025
@acicovic acicovic marked this pull request as ready for review January 21, 2025 11:42
@acicovic acicovic requested a review from a team as a code owner January 21, 2025 11:42
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 (2)
src/class-parsely.php (2)

285-286: Consider addressing the PHPStan warning.

The @phpstan-ignore return.void comment suggests there might be a type system inconsistency that could be resolved.


513-531: Consider adding timeout to the API request.

The current implementation doesn't specify a timeout for the non-blocking POST request. Consider adding a reasonable timeout value to prevent potential issues.

 $request_options = array(
     'method'      => 'POST',
     'headers'     => $headers,
     'blocking'    => false,
+    'timeout'     => 5.0,
     'body'        => $body,
     'data_format' => 'body',
 );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd93a1 and fc5c365.

📒 Files selected for processing (3)
  • src/UI/class-settings-page.php (0 hunks)
  • src/class-parsely.php (5 hunks)
  • tests/Integration/CallUpdateMetadataEndpointTest.php (1 hunks)
💤 Files with no reviewable changes (1)
  • src/UI/class-settings-page.php
🧰 Additional context used
📓 Path-based instructions (2)
src/class-parsely.php (1)

Pattern **/*.{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."
tests/Integration/CallUpdateMetadataEndpointTest.php (1)

Pattern **/*.{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."
🔇 Additional comments (13)
tests/Integration/CallUpdateMetadataEndpointTest.php (8)

1-14: LGTM! Well-structured test class setup.

The namespace, imports, and class documentation are clear and follow WordPress coding standards.


64-71: LGTM! Comprehensive credential validation test.

The test method and its data provider effectively cover all credential validation scenarios:

  • No Site ID and Metadata Secret
  • Missing Site ID only
  • Missing Metadata Secret only

Also applies to: 80-101


131-164: LGTM! Well-structured post type validation test.

The test method and its data provider effectively validate endpoint behavior for different post types:

  • Trackable: posts and pages
  • Non-trackable: attachments and revisions

188-190: LGTM! Important error case validation.

The test ensures the endpoint correctly handles non-existent post IDs.


215-234: LGTM! Thorough custom post type validation.

The test effectively validates that:

  1. Custom post types are not tracked by default
  2. Custom post types can be tracked when added to track_post_types
  3. Proper cleanup is performed by unregistering the test post type

260-275: LGTM! Good post status validation.

The test effectively validates that:

  1. Draft posts are not tracked
  2. Published posts are tracked after status update

301-321: LGTM! Comprehensive custom status validation.

The test effectively validates that:

  1. Custom statuses are not tracked by default
  2. Custom statuses can be tracked when added via filter
  3. Proper cleanup by removing the filter

332-336: LGTM! Clear helper method implementation.

The method has a clear purpose and follows WordPress coding standards.

src/class-parsely.php (5)

417-418: LGTM! Simplified status check logic.

Removing the caching mechanism eliminates potential edge cases where post status might change during request execution.


440-451: LGTM! Good credential validation.

The method properly validates required credentials before proceeding.


453-466: LGTM! Thorough post type validation.

The code effectively validates that:

  1. Post type exists
  2. Post type is in the list of tracked types

468-476: LGTM! Proper post validation.

The code validates both:

  1. Post status is trackable
  2. Post exists

478-481: LGTM! Good test environment handling.

The code properly handles integration test scenarios without making actual API calls.

Copy link
Contributor

@vaurdan vaurdan left a comment

Choose a reason for hiding this comment

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

Thank you so much for working on this. Looks good to me!

I have replied to your comments, so feel free to take a look before merging :)

@acicovic acicovic merged commit 21d49f5 into develop Jan 24, 2025
40 checks passed
@acicovic acicovic deleted the fix/update-metadata-calling-issues branch January 24, 2025 06:35
github-actions bot added a commit that referenced this pull request Jan 24, 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 Maintenance & Fixes Ticket/PR related to codebase maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants