Skip to content

Fix: make methods protected for extending#10617

Merged
lohanidamodar merged 2 commits into1.8.xfrom
fix-make-stats-usage-extendable
Oct 14, 2025
Merged

Fix: make methods protected for extending#10617
lohanidamodar merged 2 commits into1.8.xfrom
fix-make-stats-usage-extendable

Conversation

@lohanidamodar
Copy link
Copy Markdown
Member

What does this PR do?

  • Make private methods and properties protected so that we can easily extend

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 9, 2025

📝 Walkthrough

Walkthrough

This change updates src/Appwrite/Platform/Workers/StatsUsage.php by adjusting visibility from private to protected for several class members. The affected members are properties $stats, $lastTriggeredTime, $keys, $projects, $statDocuments; constants INFINITY_PERIOD, BATCH_SIZE_DEVELOPMENT, BATCH_SIZE_PRODUCTION; and methods getBatchSize() and reduce(Document $project, Document $document, array &$metrics, callable $getProjectDB). There are no alterations to method bodies, control flow, or external interfaces beyond access modifiers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title accurately reflects a key aspect of the changes by indicating that visibility is being altered to protected for extension, and it correctly conveys the intent of the pull request even though it mentions only methods and not properties or constants.
Description Check ✅ Passed The pull request description directly addresses the modifications made by explaining that private methods and properties are being changed to protected to facilitate extension.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-make-stats-usage-extendable

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 9, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.44-r2 CVE-2025-5244 HIGH
binutils 2.44-r2 CVE-2025-5245 HIGH
libxml2 2.13.8-r0 CVE-2025-49794 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49796 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49795 HIGH
libxml2 2.13.8-r0 CVE-2025-6021 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH
stdlib 1.22.10 CVE-2025-47907 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
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/Appwrite/Platform/Workers/StatsUsage.php (2)

21-26: LGTM! Consider adding documentation for extension points.

The visibility changes enable subclassing and extension of this worker class, which aligns with the PR objective. The pattern is consistent with other workers in the codebase (e.g., Audits.php).

However, consider adding PHPDoc comments to document:

  • Which properties are safe for subclasses to access or modify
  • Any constraints or invariants that subclasses should maintain
  • Whether direct property modification is intended or if accessor methods should be added in the future

This will help prevent subclasses from inadvertently breaking internal state consistency.

Also applies to: 32-32, 38-38


198-362: LGTM! Consider future refactoring for better extensibility.

Changing reduce() to protected enables subclasses to customize metric reduction logic, which aligns with the extensibility goal.

As an optional future improvement, consider refactoring this method to use a strategy pattern or template method pattern with smaller, overridable methods for each document type case. This would allow subclasses to extend specific reduction behaviors without overriding the entire method, reducing the risk of breaking core functionality.

For example:

protected function reduce(Document $project, Document $document, array &$metrics, callable $getProjectDB): void
{
    $collection = $document->getCollection();
    
    switch (true) {
        case $collection === 'users':
            $this->reduceUsers($project, $document, $metrics, $getProjectDB);
            break;
        case $collection === 'databases':
            $this->reduceDatabases($project, $document, $metrics, $getProjectDB);
            break;
        // ... other cases
    }
}

protected function reduceUsers(Document $project, Document $document, array &$metrics, callable $getProjectDB): void
{
    // Current users case logic
}
📜 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 07ce00d and 432faaf.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/StatsUsage.php (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Appwrite/Platform/Workers/StatsUsage.php (3)
src/Appwrite/Platform/Workers/Audits.php (1)
  • getBatchSize (28-31)
src/Appwrite/Utopia/Response/Model/Document.php (1)
  • Document (8-112)
app/realtime.php (1)
  • getProjectDB (76-122)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: E2E Service Test (Teams)
  • GitHub Check: E2E Service Test (Tokens)
  • GitHub Check: E2E Service Test (VCS)
  • GitHub Check: E2E Service Test (Storage)
  • GitHub Check: E2E Service Test (Realtime)
  • GitHub Check: E2E Service Test (Console)
  • GitHub Check: E2E Service Test (Health)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (Locale)
  • GitHub Check: E2E Service Test (FunctionsSchedule)
  • GitHub Check: E2E Service Test (Account)
  • GitHub Check: E2E Service Test (Databases/TablesDB)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Databases/Legacy)
  • GitHub Check: E2E Service Test (Dev Keys)
  • GitHub Check: E2E Service Test (Site Screenshots)
  • GitHub Check: Unit Test
  • GitHub Check: E2E General Test
  • GitHub Check: scan
🔇 Additional comments (1)
src/Appwrite/Platform/Workers/StatsUsage.php (1)

104-109: LGTM! Consistent with codebase pattern.

Making getBatchSize() protected allows subclasses to customize batch sizing logic, which is a reasonable extension point. This follows the same pattern used in src/Appwrite/Platform/Workers/Audits.php.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 9, 2025

✨ Benchmark results

  • Requests per second: 1,171
  • Requests with 200 status code: 210,806
  • P99 latency: 0.166366936

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,171 961
200 210,806 173,077
P99 0.166366936 0.201025275

@lohanidamodar lohanidamodar requested a review from loks0n October 12, 2025 04:32
@lohanidamodar lohanidamodar merged commit a832343 into 1.8.x Oct 14, 2025
41 checks passed
@lohanidamodar lohanidamodar deleted the fix-make-stats-usage-extendable branch October 14, 2025 00:55
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