8000 Allow compressed CSV by ItzNotABug · Pull Request #9673 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow compressed CSV #9673

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

Merged
merged 5 commits into from
Apr 21, 2025
Merged

Allow compressed CSV #9673

merged 5 commits into from
Apr 21, 2025

Conversation

ItzNotABug
Copy link
Member
@ItzNotABug ItzNotABug commented Apr 21, 2025

What does this PR do?

Files over 20MB are skipped for compressions on storage buckets. This PR allows compressed files now.

Test Plan

Manual.

Related PRs and Issues

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

  • New Features

    • Added support for importing encrypted and compressed CSV files (GZIP and Zstd) in the CSV migration process.
  • Bug Fixes

    • Improved error handling for decryption, decompression, and file writing failures during CSV import.
    • Updated error messaging to clarify that only unencrypted CSV files are supported for document import.

@ItzNotABug ItzNotABug self-assigned this Apr 21, 2025
@ItzNotABug ItzNotABug requested a review from eldadfux April 21, 2025 04:33
Copy link
coderabbitai bot commented Apr 21, 2025

Walkthrough

The update enhances the CSV migration process to support importing files that may be encrypted and/or compressed. It first detects encryption and compression attributes on the source file. If encrypted, the file is decrypted using OpenSSL with parameters from file attributes and environment variables. If compressed, the content is decompressed using either Zstd or GZIP algorithms. The resulting plaintext CSV is written to the import path. If the file is neither encrypted nor compressed, it is transferred directly. File size is now obtained from the import path. Corresponding tests were updated to reflect the use of a single bucket with encryption and gzip compression enabled and revised test cases accordingly. No changes were made to public or exported entity declarations.

Changes

File(s) Change Summary
app/controllers/api/migrations.php Added support for importing encrypted and/or compressed CSV files; decrypts with OpenSSL and decompresses with GZIP or Zstd; writes plaintext CSV to import path; updates file size retrieval.
tests/e2e/Services/Migrations/MigrationsBase.php Simplified test setup to use a single bucket with gzip compression and encryption enabled; removed tests for uncompressed/unencrypted bucket; updated bucket IDs and test references accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Controller
    participant OpenSSL
    participant Compression_Library

    Client->>API_Controller: Upload CSV file (may be encrypted/compressed)
    API_Controller->>API_Controller: Check file encryption and compression attributes
    alt File is encrypted
        API_Controller->>OpenSSL: Decrypt file content using env params
        OpenSSL-->>API_Controller: Return decrypted content
        alt File is compressed
            API_Controller->>Compression_Library: Decompress decrypted content
            Compression_Library-->>API_Controller: Return decompressed CSV
        else Not compressed
            API_Controller->>API_Controller: Use decrypted content as CSV
        end
        API_Controller->>API_Controller: Write plaintext CSV to import path
        API_Controller->>Client: Proceed with import
    else File is not encrypted
        alt File is compressed
            API_Controller->>Compression_Library: Decompress file content
            Compression_Library-->>API_Controller: Return decompressed CSV
            API_Controller->>API_Controller: Write decompressed CSV to import path
            API_Controller->>Client: Proceed with import
        else Not compressed
            API_Controller->>API_Controller: Transfer file directly to import path
            API_Controller->>Client: Proceed with import
        end
    end
Loading

Poem

A CSV wrapped tight,
Encrypted out of sight,
But now with keys and codes,
It sheds its secret loads.
Compressed in gzip or zstd flair,
Decrypted, decompressed with care—
Migration hops with joy to share! 🐇📄✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 927489b and 53a0424.

📒 Files selected for processing (1)
  • tests/e2e/Services/Migrations/MigrationsBase.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/e2e/Services/Migrations/MigrationsBase.php
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: E2E Service Test (Webhooks)
  • GitHub Check: E2E Service Test (Migrations)
  • GitHub Check: E2E Service Test (Storage)
  • GitHub Check: E2E Service Test (Teams)
  • GitHub Check: E2E Service Test (Realtime)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (Account)
  • GitHub Check: E2E Service Test (Projects)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Proxy)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (Health)
  • GitHub Check: E2E Service Test (Databases)
  • GitHub Check: E2E Service Test (Console)
  • GitHub Check: E2E Service Test (Locale)
  • GitHub Check: Benchmark
  • GitHub Check: E2E General Test
  • GitHub Check: Unit Test
  • GitHub Check: scan

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.
    • 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.
  • @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 automa 8000 tically.

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
github-actions bot commented Apr 21, 2025

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
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
@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)
app/controllers/api/migrations.php (2)

354-356: Consider updating the comment to match PR objectives.

The comment suggests compression is skipped on files larger than 20MB, but the PR objective states this update allows compression for files over 20MB. This creates a potential contradiction.

-$hasCompression = $compression !== Compression::NONE; // skipped on files that are 20MB+ in size.
+$hasCompression = $compression !== Compression::NONE; // now supporting compression for all file sizes

361-375: Add a default case to handle unsupported compression algorithms.

The switch statement doesn't handle cases where the compression algorithm might be something unexpected. Adding a default case would make the code more robust.

    switch ($compression) {
        case Compression::ZSTD:
            $source = (new Zstd())->decompress($source);
            break;
        case Compression::GZIP:
            $source = (new GZIP())->decompress($source);
            break;
+       default:
+           throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED, "Unsupported compression algorithm: {$compression}");
    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61868a9 and 873b384.

📒 Files selected for processing (1)
  • app/controllers/api/migrations.php (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (4)
app/controllers/api/migrations.php (4)

30-31: Appropriate import additions for compression support.

These imports enable support for the new compression algorithms (GZIP and Zstd) used in the CSV migration endpoint.


350-352: Improved file restriction logic.

The code now only rejects files encrypted with OpenSSL rather than rejecting all compressed files. This change aligns with the PR objective to support compression for larger files.


376-378: Good error handling for file transfer.

The error handling for both compressed and uncompressed files is consistent and appropriate.


380-380: Correct file size determination from decompressed file.

Now correctly determining the file size from the decompressed file in the import path, which is essential for accurate reporting and processing.

Copy link
github-actions bot commented Apr 21, 2025

✨ Benchmark results

  • Requests per second: 915
  • Requests with 200 status code: 164,801
  • P99 latency: 0.203077986

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 915 1,234
200 164,801 222,085
P99 0.203077986 0.152329465

Copy link
@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: 3

🧹 Nitpick comments (1)
app/controllers/api/migrations.php (1)

352-356: Inline comment is now misleading – please update for clarity

The // no encryption, compression on files above 20MB. remark reflects the previous behaviour that skipped processing for large files.
Because the surrounding logic now actively supports decrypting / decompressing any size, this sentence will confuse future readers.

-        // no encryption, compression on files above 20MB.
+        // Detect whether the file was stored with encryption and/or compression.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0accc49 and 927489b.

📒 Files selected for processing (1)
  • app/controllers/api/migrations.php (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan

@eldadfux eldadfux merged commit 0bf2318 into 1.7.x Apr 21, 2025
34 checks passed
@ItzNotABug ItzNotABug deleted the allow-compressed-csv branch April 21, 2025 10:03
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
0