Skip to content

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Jul 22, 2025

Reverts #611

Summary by CodeRabbit

  • Refactor
    • The document update process now always synchronizes permissions during updates. The option to skip permission handling has been removed, ensuring that permission changes are consistently applied whenever a document is updated. No changes to the user interface or workflows.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

The changes remove the $skipPermissions boolean parameter from the updateDocument method across all relevant classes and adapters. Permission updates are now always processed during document updates, with all conditional logic and related parameter handling for skipping permissions removed from the codebase.

Changes

File(s) Change Summary
src/Database/Adapter.php Removed $skipPermissions parameter from abstract updateDocument method and updated PHPDoc.
src/Database/Adapter/MariaDB.php
src/Database/Adapter/Postgres.php
src/Database/Adapter/SQLite.php
Removed $skipPermissions parameter from updateDocument signatures; made permission updates unconditional.
src/Database/Adapter/Pool.php Removed $skipPermissions parameter from updateDocument; updated delegation logic.
src/Database/Database.php Removed logic for comparing permissions and $skipPermissionsUpdate flag; always updates permissions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Database
    participant Adapter
    participant Storage

    Client->>Database: updateDocument(collection, id, document)
    Database->>Adapter: updateDocument(collection, id, document)
    Adapter->>Storage: Update document data
    Adapter->>Storage: Always update permissions
    Storage-->>Adapter: Update result
    Adapter-->>Database: Updated Document
    Database-->>Client: Updated Document
Loading

Estimated code review effort

3 (~45 minutes)

Possibly related PRs

  • Skip permissions update #611: This PR originally introduced the $skipPermissions parameter and conditional permission skipping logic, which is now being reversed.

Poem

In the warren where code bunnies dwell,
We hop through permissions, no longer a spell—
No skipping, no toggling, just always in sync,
Update those docs with a nod and a wink.
🐇✨
Now every permission gets its due,
Hooray for a codebase that's simpler too!


📜 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 239b19b and b96fa84.

📒 Files selected for processing (6)
  • src/Database/Adapter.php (1 hunks)
  • src/Database/Adapter/MariaDB.php (2 hunks)
  • src/Database/Adapter/Pool.php (1 hunks)
  • src/Database/Adapter/Postgres.php (2 hunks)
  • src/Database/Adapter/SQLite.php (2 hunks)
  • src/Database/Database.php (1 hunks)
🧬 Code Graph Analysis (2)
src/Database/Adapter/MariaDB.php (7)
src/Database/Adapter.php (4)
  • updateDocument (703-703)
  • getTenantQuery (1210-1210)
  • trigger (429-439)
  • execute (1216-1216)
src/Database/Adapter/Pool.php (4)
  • updateDocument (238-241)
  • getTenantQuery (488-491)
  • trigger (93-96)
  • execute (493-496)
src/Database/Adapter/SQLite.php (1)
  • updateDocument (638-843)
src/Database/Adapter/Postgres.php (2)
  • updateDocument (1055-1253)
  • execute (86-106)
src/Database/Database.php (3)
  • updateDocument (4115-4300)
  • trigger (579-597)
  • Database (35-6801)
src/Database/Document.php (2)
  • Document (12-460)
  • getPermissionsByType (135-147)
src/Database/Adapter/SQL.php (3)
  • getTenantQuery (1663-1695)
  • getPDO (1552-1555)
  • execute (1766-1769)
src/Database/Database.php (5)
src/Database/Adapter.php (1)
  • updateDocument (703-703)
src/Database/Adapter/Pool.php (1)
  • updateDocument (238-241)
src/Database/Adapter/SQLite.php (1)
  • updateDocument (638-843)
src/Database/Adapter/Postgres.php (1)
  • updateDocument (1055-1253)
src/Database/Adapter/MariaDB.php (1)
  • updateDocument (935-1148)
🪛 PHPMD (2.15.0)
src/Database/Adapter/Postgres.php

1055-1055: Avoid unused parameters such as '$id'. (Unused Code Rules)

(UnusedFormalParameter)


1170-1170: Avoid unused local variables such as '$_'. (Unused Code Rules)

(UnusedLocalVariable)

src/Database/Adapter/SQLite.php

756-756: Avoid unused local variables such as '$_'. (Unused Code Rules)

(UnusedLocalVariable)

src/Database/Adapter/MariaDB.php

935-935: Avoid unused parameters such as '$id'. (Unused Code Rules)

(UnusedFormalParameter)


1051-1051: Avoid unused local variables such as '$_'. (Unused Code Rules)

(UnusedLocalVariable)

🧰 Additional context used
🧬 Code Graph Analysis (2)
src/Database/Adapter/MariaDB.php (7)
src/Database/Adapter.php (4)
  • updateDocument (703-703)
  • getTenantQuery (1210-1210)
  • trigger (429-439)
  • execute (1216-1216)
src/Database/Adapter/Pool.php (4)
  • updateDocument (238-241)
  • getTenantQuery (488-491)
  • trigger (93-96)
  • execute (493-496)
src/Database/Adapter/SQLite.php (1)
  • updateDocument (638-843)
src/Database/Adapter/Postgres.php (2)
  • updateDocument (1055-1253)
  • execute (86-106)
src/Database/Database.php (3)
  • updateDocument (4115-4300)
  • trigger (579-597)
  • Database (35-6801)
src/Database/Document.php (2)
  • Document (12-460)
  • getPermissionsByType (135-147)
src/Database/Adapter/SQL.php (3)
  • getTenantQuery (1663-1695)
  • getPDO (1552-1555)
  • execute (1766-1769)
src/Database/Database.php (5)
src/Database/Adapter.php (1)
  • updateDocument (703-703)
src/Database/Adapter/Pool.php (1)
  • updateDocument (238-241)
src/Database/Adapter/SQLite.php (1)
  • updateDocument (638-843)
src/Database/Adapter/Postgres.php (1)
  • updateDocument (1055-1253)
src/Database/Adapter/MariaDB.php (1)
  • updateDocument (935-1148)
🪛 PHPMD (2.15.0)
src/Database/Adapter/Postgres.php

1055-1055: Avoid unused parameters such as '$id'. (Unused Code Rules)

(UnusedFormalParameter)


1170-1170: Avoid unused local variables such as '$_'. (Unused Code Rules)

(UnusedLocalVariable)

src/Database/Adapter/SQLite.php

756-756: Avoid unused local variables such as '$_'. (Unused Code Rules)

(UnusedLocalVariable)

src/Database/Adapter/MariaDB.php

935-935: Avoid unused parameters such as '$id'. (Unused Code Rules)

(UnusedFormalParameter)


1051-1051: Avoid unused local variables such as '$_'. (Unused Code Rules)

(UnusedLocalVariable)

🔇 Additional comments (12)
src/Database/Adapter/Pool.php (1)

238-241: LGTM: Method signature updated consistently with the broader refactor.

The removal of the $skipPermissions parameter aligns with the system-wide change to always process permission updates during document updates. The Pool adapter correctly delegates to the underlying adapter with the updated signature.

src/Database/Adapter.php (1)

694-703: LGTM: Abstract method signature updated to enforce mandatory permission updates.

The removal of the $skipPermissions parameter from the abstract updateDocument method enforces that all concrete adapter implementations must now always process permission updates during document updates. This change aligns perfectly with the PR objective to revert the "skip permissions update" functionality.

src/Database/Database.php (1)

4285-4285: LGTM! Adapter call now correctly matches the interface.

The removal of the $skipPermissionsUpdate parameter from the adapter call correctly aligns with the abstract adapter interface, which expects only three parameters: collection, id, and Document. This change ensures that permission updates are now always processed during document updates, which is consistent with the revert objective.

src/Database/Adapter/Postgres.php (5)

1055-1055: Method signature correctly updated for the revert.

The removal of the $skipPermissions parameter aligns with the PR objective to revert the "Skip permissions update" functionality. Permission updates are now mandatory during document updates.

Note: The static analysis hint about unused parameter $id is a false positive - this parameter is actively used throughout the method for binding values in prepared statements.


1065-1087: Permission querying logic is correct.

The code properly queries current permissions from the database with appropriate parameter binding and tenant handling for shared tables. The cursor is closed properly after fetching results.


1088-1119: Permission processing logic is well-implemented.

The code correctly:

  • Initializes permission arrays for all types
  • Organizes fetched permissions by type using array_reduce
  • Calculates permission removals and additions using array_diff
  • Handles the logic flow appropriately

1120-1162: Permission removal logic is correctly implemented.

The code properly:

  • Builds dynamic removal queries only when removals exist
  • Uses proper parameter binding with unique keys
  • Handles tenant scenarios appropriately
  • Executes removal statements conditionally

1164-1195: Permission addition logic is correctly implemented.

The code properly builds dynamic insertion queries with parameter binding and tenant handling.

The static analysis hint about unused variable $_ at line 1170 is a false positive - this is a standard PHP pattern where you need the array index ($i) for parameter binding but don't need the actual value in that specific loop iteration.

src/Database/Adapter/MariaDB.php (3)

935-935: LGTM: Method signature correctly updated to remove skipPermissions parameter.

This change aligns with the PR objective to revert the "Skip permissions update" functionality, making permission synchronization mandatory during document updates.


946-1001: LGTM: Permission synchronization logic is well-structured.

The code correctly:

  • Fetches current permissions from the database
  • Calculates permission removals and additions by comparing current DB state with document permissions
  • Handles tenant bindings appropriately for shared tables
  • Transforms permissions into a structured format for efficient processing

1002-1091: LGTM: Permission removal and addition SQL logic is properly implemented.

The code correctly:

  • Builds dynamic SQL queries for permission removals and additions
  • Uses proper parameter binding to prevent SQL injection
  • Handles tenant bindings for shared table scenarios
  • Triggers events for observability
  • The unused variable $_ at line 1051 is intentional (common PHP pattern for ignored loop variables)
src/Database/Adapter/SQLite.php (1)

638-782: LGTM: SQLite adapter changes are consistent with MariaDB implementation.

The changes correctly:

  • Remove the $skipPermissions parameter from the method signature
  • Implement mandatory permission synchronization during document updates
  • Follow the same logical flow as the MariaDB adapter: fetch current permissions, calculate diffs, execute SQL
  • Handle SQLite-specific syntax appropriately (table name quoting, etc.)
  • Update exception annotations to reflect actual exceptions thrown

The unused variable $_ at line 756 flagged by static analysis is intentional (standard PHP pattern for ignored loop variables).

✨ 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.

@abnegate abnegate merged commit ad7613a into main Jul 22, 2025
15 checks passed
@abnegate abnegate deleted the revert-611-optimize-update-document branch July 22, 2025 03:13
This was referenced Jul 24, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 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.

2 participants