Skip to content

Feat sync 1.6#9920

Merged
abnegate merged 13 commits into1.7.xfrom
feat-sync-1.6
May 28, 2025
Merged

Feat sync 1.6#9920
abnegate merged 13 commits into1.7.xfrom
feat-sync-1.6

Conversation

@abnegate
Copy link
Copy Markdown
Member

@abnegate abnegate commented May 28, 2025

What does this PR do?

(Provide a description of what this PR does and why it's needed.)

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?

Summary by CodeRabbit

  • Bug Fixes

    • Enabled full coroutine support, including TCP hooks, for improved performance and compatibility.
  • Refactor

    • Standardized file size limits and buffer sizes in storage endpoints by replacing hardcoded values with a unified constant.
    • Improved consistency of HTTP response headers in file preview and download endpoints by adjusting header placement after range processing.
    • Simplified internal scheduling logic by removing unused parameters from scheduling methods, resulting in cleaner and more maintainable code.

basert and others added 13 commits May 21, 2025 10:57
This prevents requests with `Range: 0-<file length>` and limits it to APP_STORAGE_READ_BUFFER
fix(storage): do not allow full range
added encrypt property in the attribute string response model
added checking for encrypt and plan allowing encryption of string att…
# Conflicts:
#	composer.lock
#	src/Appwrite/Platform/Workers/Builds.php
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

The changes update coroutine hook settings to enable all hooks, standardize storage buffer size constants, and improve HTTP header handling order in storage endpoints. Additionally, several scheduling task methods and closures are refactored to remove unnecessary $pools parameters and references, simplifying method signatures and closure captures.

Changes

File(s) Change Summary
app/cli.php Enables coroutines with all Swoole hooks, including TCP, by removing previous exclusions and related comments.
app/controllers/api/storage.php Replaces hardcoded buffer sizes with APP_STORAGE_READ_BUFFER; moves HTTP header setting after range handling.
src/Appwrite/Platform/Tasks/ScheduleBase.php Removes Group $pools parameter from collectSchedules method and its invocations; updates method signature.
src/Appwrite/Platform/Tasks/ScheduleFunctions.php, src/Appwrite/Platform/Tasks/ScheduleMessages.php Removes $pools from closure use clauses in scheduling resource enqueuing methods.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StorageController
    participant Response

    User->>StorageController: Request file (download/view/push)
    StorageController->>StorageController: Handle range requests, set buffer size using APP_STORAGE_READ_BUFFER
    StorageController->>StorageController: Set HTTP headers after range validation
    StorageController->>Response: Send file content with correct headers
Loading
sequenceDiagram
    participant Scheduler
    participant ScheduleBase
    participant ScheduleFunctions
    participant ScheduleMessages

    Scheduler->>ScheduleBase: action()
    ScheduleBase->>ScheduleBase: collectSchedules(dbForPlatform, getProjectDB, lastSyncUpdate)
    ScheduleBase->>ScheduleFunctions: enqueueResources(schedules, dbForPlatform)
    ScheduleBase->>ScheduleMessages: enqueueResources(schedules, dbForPlatform)
Loading

Poem

In the warren of code, a buffer grows,
Magic numbers fade as a new constant shows.
Coroutines hop, TCP hooks now in tow,
Schedules trimmed, pools let go.
Headers set right, after ranges are checked—
A tidy spring cleaning, as rabbits expect! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@github-actions
Copy link
Copy Markdown

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between af6499b and 9cd5213.

📒 Files selected for processing (5)
  • app/cli.php (1 hunks)
  • app/controllers/api/storage.php (7 hunks)
  • src/Appwrite/Platform/Tasks/ScheduleBase.php (3 hunks)
  • src/Appwrite/Platform/Tasks/ScheduleFunctions.php (1 hunks)
  • src/Appwrite/Platform/Tasks/ScheduleMessages.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/Appwrite/Platform/Tasks/ScheduleBase.php (2)
app/realtime.php (1)
  • getProjectDB (76-122)
src/Appwrite/Utopia/Response/Model/Document.php (1)
  • Document (8-92)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (12)
app/cli.php (1)

287-287: LGTM: TCP hooks enabled for coroutines.

The change enables TCP hooks that were previously excluded from coroutine execution. This aligns with the broader refactoring in the scheduling system to improve coroutine and resource pool handling.

src/Appwrite/Platform/Tasks/ScheduleFunctions.php (1)

79-79: LGTM: Removed unused $pools parameter.

The $pools variable was not used within the closure, so removing it from the use clause is a good cleanup that reduces unnecessary variable capture.

src/Appwrite/Platform/Tasks/ScheduleMessages.php (1)

43-43: LGTM: Removed unused $pools parameter.

The $pools variable was not used within the closure, so removing it from the use clause is appropriate cleanup that eliminates unnecessary variable capture.

src/Appwrite/Platform/Tasks/ScheduleBase.php (3)

82-82: LGTM: Updated method calls to match new signature.

The calls to collectSchedules have been properly updated to remove the $pools parameter, maintaining consistency with the updated method signature.

Also applies to: 88-88, 91-91


106-106: LGTM: Removed unused parameter from method signature.

The Group $pools parameter was not used within the collectSchedules method implementation, so removing it simplifies the method signature and reduces unnecessary dependencies.


118-118: LGTM: Removed unused variable from closure.

The $pools variable was not used within the $getSchedule closure, so removing it from the use clause is appropriate cleanup.

app/controllers/api/storage.php (6)

1189-1189: Good standardization of buffer size constant.

Replacing the hardcoded 2MB limit with APP_STORAGE_READ_BUFFER improves code consistency and maintainability. This ensures all buffer size limits use the same constant throughout the codebase.


1356-1357: Consistent improvement across endpoints.

Good to see the same buffer size standardization applied consistently across the getFileView endpoint, matching the changes in getFileDownload.


1371-1378: Consistent header reordering pattern.

The header setting has been moved after range processing in getFileView, consistent with the changes in getFileDownload. The same verification regarding header ordering safety applies here.


1509-1510: Complete consistency across file serving endpoints.

Excellent consistency - all three file serving endpoints (getFileDownload, getFileView, getFilePush) now use the same buffer size constant for range handling.


1524-1530: Consistent header reordering completed.

The header setting pattern is now consistent across all file serving endpoints. All three endpoints (getFileDownload, getFileView, getFilePush) now set response headers after range processing.


1007-1007:

Details

✅ Verification successful

Verify that APP_STORAGE_READ_BUFFER constant is defined and has appropriate value.

The hardcoded preview limit fallback has been replaced with APP_STORAGE_READ_BUFFER. Ensure this constant is properly defined and has a suitable value for preview size limits.


🏁 Script executed:

#!/bin/bash
# Description: Verify APP_STORAGE_READ_BUFFER constant definition and usage
# Expected: The constant should be defined and used consistently across the codebase

# Search for the constant definition
echo "=== Searching for APP_STORAGE_READ_BUFFER definition ==="
rg -A 2 -B 2 "define.*APP_STORAGE_READ_BUFFER|APP_STORAGE_READ_BUFFER.*=" 

# Search for all usages to ensure consistency
echo -e "\n=== All usages of APP_STORAGE_READ_BUFFER ==="
rg -A 1 -B 1 "APP_STORAGE_READ_BUFFER"

# Check if there are any remaining hardcoded values that should use this constant
echo -e "\n=== Checking for potential hardcoded values that should use the constant ==="
rg -A 2 -B 2 "\b(20000000|2000000)\b"

Length of output: 12521


APP_STORAGE_READ_BUFFER is properly defined and matches the previous 20 MB fallback

The constant APP_STORAGE_READ_BUFFER is declared in app/init/constants.php as:

const APP_STORAGE_READ_BUFFER = 20 * (1000 * 1000); // 20MB

Its value is identical to the former hardcoded 20 MB, and it’s used consistently throughout the storage API. No further changes are required for the preview‐limit check.

Comment on lines +1204 to +1209
$response
->setContentType($file->getAttribute('mimeType'))
->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days
->addHeader('X-Peak', \memory_get_peak_usage())
->addHeader('Content-Disposition', 'attachment; filename="' . $file->getAttribute('name', '') . '"')
;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify that moving header setting after range processing doesn't cause issues.

The HTTP response headers are now set after range handling logic instead of before. While the range processing appears to only set headers without sending the response, this reordering could potentially affect response construction or header precedence.


🏁 Script executed:

#!/bin/bash
# Description: Check for any response sending or header conflicts in range processing
# Expected: Range processing should only set headers, not send response

echo "=== Checking range processing logic for response operations ==="
# Look for response send/output operations in range handling
rg -A 5 -B 5 "(response.*send|response.*output|response.*chunk)" app/controllers/api/storage.php

echo -e "\n=== Checking header setting patterns in other endpoints ==="
# Check if other endpoints follow similar patterns
rg -A 10 -B 5 "setContentType.*addHeader.*Cache-Control" app/controllers/api/storage.php

Length of output: 4574


Fix header placement in download endpoint

The response headers (Content-Type, Cache-Control, X-Peak, Content-Disposition) are currently added after calls to $response->send() and $response->chunk(), so any partial (range) or chunked responses will be sent without those headers. Move the header setup to before the range-handling logic to ensure all responses include them.

• File: app/controllers/api/storage.php
Endpoint: GET /v1/storage/buckets/:bucketId/files/:fileId/download (around lines 1180–1209)

Suggested diff:

--- a/app/controllers/api/storage.php
+++ b/app/controllers/api/storage.php
@@ -1180,6 +1180,12 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download')
+    // Set response headers before any send()/chunk()
+    $response
+        ->setContentType($file->getAttribute('mimeType'))
+        ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days
+        ->addHeader('X-Peak', \memory_get_peak_usage())
+        ->addHeader('Content-Disposition', 'attachment; filename="' . $file->getAttribute('name', '') . '"');
+
     // Range and body handling
     if (!empty($rangeHeader)) {
         $response->send(substr($source, $start, $end - $start + 1));

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/controllers/api/storage.php around lines 1204 to 1209, the response
headers such as Content-Type, Cache-Control, X-Peak, and Content-Disposition are
being set after calls to $response->send() and $response->chunk(), causing
partial or chunked responses to be sent without these headers. To fix this, move
the header-setting code to before any range processing or response sending logic
in the download endpoint so that all responses include the necessary headers
consistently.

@github-actions
Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 980
  • Requests with 200 status code: 176,439
  • P99 latency: 0.187964253

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 980 1,118
200 176,439 201,219
P99 0.187964253 0.166761035

@abnegate abnegate merged commit 61f0e5b into 1.7.x May 28, 2025
38 checks passed
@abnegate abnegate deleted the feat-sync-1.6 branch May 28, 2025 09:12
@coderabbitai coderabbitai bot mentioned this pull request Jun 3, 2025
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.

4 participants