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

enhance: Add analytics cache modifier for seller analytics filter. #2529

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

MdAsifHossainNadim
Copy link
Contributor

@MdAsifHossainNadim MdAsifHossainNadim commented Jan 24, 2025

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

Analytics Reports

Closes

  • Closes #

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • New Features

    • Enhanced analytics reporting with seller-specific filtering
    • Added cache key modification service for analytics queries
  • Chores

    • Minor code formatting adjustment in BaseQueryFilter
    • Added new service provider configuration for analytics
  • Refactor

    • Improved analytics data retrieval and filtering mechanism

@MdAsifHossainNadim MdAsifHossainNadim self-assigned this Jan 24, 2025
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

This pull request introduces a new CacheKeyModifier class in the Dokan analytics reporting system. The changes include adding a service provider entry for the new class, which is designed to filter seller analytics data by modifying query arguments in WooCommerce analytics reports. A minor formatting adjustment was also made in the BaseQueryFilter class, removing an extra space before a null coalescing operator.

Changes

File Change Summary
includes/Analytics/Reports/BaseQueryFilter.php Removed extra space in null coalescing operator line
includes/DependencyManagement/Providers/AnalyticsServiceProvider.php Added new service CacheKeyModifier::class to $services array
includes/Analytics/Reports/CacheKeyModifier.php New file introducing CacheKeyModifier class for filtering seller analytics data

Sequence Diagram

sequenceDiagram
    participant SP as ServiceProvider
    participant CM as CacheKeyModifier
    participant WC as WooCommerce Analytics
    
    SP->>CM: Register Service
    CM->>CM: Setup Entities
    CM->>CM: Register Hooks
    WC->>CM: Request Analytics
    CM->>CM: Apply Seller Filter
    CM-->>WC: Return Filtered Query Args
Loading

Possibly related PRs

Suggested labels

QA approved, :+1: Dev Review Done

Suggested reviewers

  • mrabbani

Poem

🐰 Hop, hop, through code so bright,
Analytics filters take their flight!
A cache key tweak, a vendor's delight,
Dokan's magic works with all its might,
Reporting now with rabbit's insight! 🔍


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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 (3)
includes/Analytics/Reports/SellerDataModifier.php (3)

12-22: Replace version placeholders or define dedicated constants

Currently, the doc tags use DOKAN_SINCE. Please replace it with the actual plugin version or define a constant for better clarity.


39-59: Consider extracting entity definitions

Defining these analytics entities in a single array is straightforward. For scalability, consider extracting them into constants or a dedicated config to streamline maintainability.


99-110: Add coverage for seller filtering

Consider writing unit or integration tests to ensure the seller filtering logic behaves correctly for valid, invalid, and edge-case seller IDs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00d3c5d and b62ddc9.

📒 Files selected for processing (3)
  • includes/Analytics/Reports/BaseQueryFilter.php (1 hunks)
  • includes/Analytics/Reports/SellerDataModifier.php (1 hunks)
  • includes/DependencyManagement/Providers/AnalyticsServiceProvider.php (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • includes/Analytics/Reports/BaseQueryFilter.php
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: api tests (1, 1)
🔇 Additional comments (4)
includes/DependencyManagement/Providers/AnalyticsServiceProvider.php (1)

27-27: Add new service

This new entry ensures that the SellerDataModifier is managed by the container. The approach is consistent, looks clean, and integrates well with your existing architecture.

includes/Analytics/Reports/SellerDataModifier.php (3)

23-30: Constructor hooking is acceptable

Calling setup_entities() and register_hooks() directly in the constructor ensures the hooks are registered upon instantiation. This is fine for now, but if performance or flexibility become issues, consider lazy hooking.


68-72: Hooks are registered correctly

Attaching each entity’s filter via the WordPress hook API is implemented properly.


88-97: Verify usage of Stock\QueryFilter for vendor ID retrieval

Confirm that calling Stock\QueryFilter::class to retrieve the seller ID is the intended approach. If a more dedicated or generic method to retrieve the seller ID exists, consider using it for clarity.

✅ Verification successful

Stock\QueryFilter is the correct choice for vendor ID retrieval

The implementation is appropriate as Stock\QueryFilter extends BaseQueryFilter, inheriting proper permission checks, and is specifically designed for stock analytics context. The usage is consistent with other stock-related analytics components in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for other potential definitions of get_vendor_id across the codebase
rg -A 5 'function get_vendor_id'

Length of output: 1965


Script:

#!/bin/bash
# Check Stock\QueryFilter's implementation and inheritance
ast-grep --pattern 'class QueryFilter extends $_' includes/Analytics/Reports/Stock/QueryFilter.php
cat includes/Analytics/Reports/Stock/QueryFilter.php

Length of output: 1637

@MdAsifHossainNadim MdAsifHossainNadim added Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing labels Jan 24, 2025
@MdAsifHossainNadim MdAsifHossainNadim changed the title enhance: Add seller analytic stats modifier for seller analytics filter. enhance: Add analytic cache modifier for seller analytics filter. Jan 24, 2025
@MdAsifHossainNadim MdAsifHossainNadim changed the title enhance: Add analytic cache modifier for seller analytics filter. enhance: Add analytics cache modifier for seller analytics filter. Jan 24, 2025
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 (6)
includes/Analytics/Reports/CacheKeyModifier.php (6)

7-11: Specify the “@SInCE” version.

The docblock comments reference DOKAN_SINCE, but the actual plugin version is not specified. Please replace DOKAN_SINCE with the correct version number to enhance clarity and maintain consistent documentation references.


27-30: Consider deferring hook registration.

Registering hooks in the constructor may be too early for some scenarios, potentially leading to race conditions if other services aren’t yet loaded. Consider deferring the hook registration to a dedicated init method triggered after the plugin is fully initialized.


73-75: Add error handling for unrecognized entities.

If $this->entities contains strings that don’t match known analytics entities, the filter registration could fail silently. Consider adding checks or logging to provide feedback when encountering unrecognized entities.


92-92: Avoid direct container calls in the method body.

Directly calling dokan()->get_container()->get(...) in this method couples the code to the container. For improved testability and maintainability, inject the needed dependencies into the constructor instead of resolving them at call time.


99-99: Clarify usage of the seller_id array key.

Adding 'seller_id' to $args might conflict with existing keys or reserved parameters in analytics queries. Consider using a more descriptive key (e.g., 'dokan_seller_id') to avoid potential collisions.


112-114: Enhance seller validation.

Currently, is_valid_seller_id checks only for a numeric value greater than zero. If needed, extend validation logic to ensure the user exists and has the required seller capabilities.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a91977b and 6b0f401.

📒 Files selected for processing (2)
  • includes/Analytics/Reports/CacheKeyModifier.php (1 hunks)
  • includes/DependencyManagement/Providers/AnalyticsServiceProvider.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/DependencyManagement/Providers/AnalyticsServiceProvider.php
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: api tests (1, 1)
🔇 Additional comments (1)
includes/Analytics/Reports/CacheKeyModifier.php (1)

21-21: Ensure backward compatibility with typed properties.

Typed properties (protected array $entities;) require PHP 7.4 or higher. If the plugin aims to support older PHP versions, consider removing the type declaration or providing a polyfill. Otherwise, document the required PHP version.

@mrabbani mrabbani added 👍 Dev Review Done and removed Needs: Dev Review It requires a developer review and approval labels Jan 24, 2025
@shashwatahalder01 shashwatahalder01 added QA In Progress and removed Needs: Testing This requires further testing labels Jan 28, 2025
@shashwatahalder01 shashwatahalder01 added QA approved This PR is approved by the QA team and removed QA In Progress labels Jan 28, 2025
@shohag121 shohag121 merged commit 29a4554 into develop Jan 28, 2025
6 checks passed
@shohag121 shohag121 deleted the enhance/add-seller-analytics-stats-modifier branch January 28, 2025 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants