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

fix: change Element's methods visibility #356

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

fominok
Copy link
Collaborator

@fominok fominok commented Jan 23, 2025

Changed visibility of several Element's methods to crate only and cleaned up those that became unused.

Issue being fixed or feature implemented

GroveDb has huge public API, but in practice only a part shall be used by users. This PR is an attempt to address those visibility issues in element module.

What was done?

Visibility of methods of Element except constructors was changed from pub to pub (crate), that revealed dead code that was deleted as well.

How Has This Been Tested?

  • GroveDb tests
  • Platform tests using this branch

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

Release Notes

  • Refactor

    • Restricted visibility of multiple methods in the Element implementation across different modules
    • Removed several public methods related to querying, getting, inserting, and deleting elements
    • Reduced external access to internal database operations
  • Changes

    • Methods in delete.rs, exists.rs, get.rs, insert.rs, and query.rs have been changed from pub to pub(crate)
    • Simplified method access and improved internal encapsulation of database functionality

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request introduces significant changes to the Element implementation across multiple files in the grovedb/src/element/ directory. The primary modifications involve changing method visibilities from pub to pub(crate), effectively restricting access to methods within the current crate. Several methods have been removed entirely, including delete, get_with_absolute_refs, get_query, get_query_values, and get_sized_query. These changes aim to improve encapsulation and control over the Element struct's functionality, limiting external access to certain methods while maintaining core implementation details.

Changes

File Changes
delete.rs - Removed delete method
- Changed delete_with_sectioned_removal_bytes to pub(crate)
- Changed delete_into_batch_operations to pub(crate)
exists.rs - Changed element_at_key_already_exists to pub(crate)
get.rs - Changed multiple methods to pub(crate): get, get_optional, get_from_storage, get_optional_from_storage, get_with_value_hash
- Removed get_with_absolute_refs method
insert.rs - Changed multiple methods to pub(crate): insert, insert_into_batch_operations, insert_reference, insert_subtree
- Removed insert_if_not_exists and insert_if_changed_value methods
query.rs - Removed get_query, get_query_values, get_sized_query
- Changed get_query_apply_function to pub(crate)
- Changed iterator to pub(crate)
- Changed ElementsIterator methods to pub(crate)

Possibly related PRs

Suggested reviewers

  • QuantumExplorer

Poem

🐰 A Rabbit's Ode to Code Encapsulation 🔒

Methods hidden, visibility tight,
Crate-private functions shine so bright
Removing paths that wandered far
Our Element now, a guarded star!

Hop, hop, refactor with glee! 🚀


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 (1)
grovedb/src/element/query.rs (1)

888-942: Refactor test helper functions to align with new API

The helper functions get_query and get_query_values are recreated within the test module to preserve existing test cases after the removal of their public counterparts. Consider refactoring the tests to directly use the updated internal methods or expose necessary functionality through public interfaces. This would reduce code duplication and enhance maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 44c2244 and e57335b.

📒 Files selected for processing (5)
  • grovedb/src/element/delete.rs (2 hunks)
  • grovedb/src/element/exists.rs (1 hunks)
  • grovedb/src/element/get.rs (6 hunks)
  • grovedb/src/element/insert.rs (12 hunks)
  • grovedb/src/element/query.rs (24 hunks)
🔇 Additional comments (22)
grovedb/src/element/query.rs (3)

Line range hint 235-318: Verify external usage of get_query_apply_function

The method get_query_apply_function has been changed to pub(crate), restricting its visibility to within the crate. Please ensure that no external crates or modules depend on this function. If external access is required, consider providing a public wrapper or updating the documentation to reflect this change.


Line range hint 320-429: Ensure get_path_query visibility change does not affect external code

The function get_path_query is now pub(crate). Verify that this change does not impact any external components that might rely on this method. If external use is intended, consider maintaining its public visibility or offering alternative public methods.


861-863: Check for external dependencies on iterator method

The visibility of the iterator method has been changed to pub(crate). Ensure that no external code relies on this method. If it is part of the public API, you might need to retain its public visibility or provide an alternative interface.

grovedb/src/element/exists.rs (1)

Line range hint 14-22: Confirm internal sufficiency of element_at_key_already_exists

The method element_at_key_already_exists is now pub(crate). Please verify that this change does not affect any external modules or crates relying on this function. If external access is necessary, consider providing a public interface.

grovedb/src/element/delete.rs (3)

Line range hint 23-87: Review the impact of removing the public delete method

The delete method has been removed. Ensure that this does not break any external dependencies. If external code relies on this method, consider providing an alternative public method or updating the documentation to inform users of the change.


Line range hint 23-87: Assess the visibility change of delete_with_sectioned_removal_bytes

The method delete_with_sectioned_removal_bytes is now pub(crate). Verify that this change aligns with the intended encapsulation and does not affect any external usage. If external access is required, consider exposing a public method or updating the API accordingly.


Line range hint 89-106: Ensure no external dependence on delete_into_batch_operations

Changing delete_into_batch_operations to pub(crate) restricts its usage to within the crate. Please confirm that no external modules depend on this function. If it needs to be accessible externally, consider keeping it public or providing an alternative.

grovedb/src/element/get.rs (6)

Line range hint 33-63: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 64-103: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 104-126: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 127-317: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate. The version-specific implementations are well-handled.


Line range hint 318-355: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 356-399: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.

grovedb/src/element/insert.rs (9)

Line range hint 22-79: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 80-122: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 123-171: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 172-209: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 210-261: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 262-296: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 297-352: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 353-399: LGTM! Visibility change aligns with PR objectives.

The visibility change from pub to pub(crate) helps limit the public API surface while maintaining proper functionality within the crate.


Line range hint 467-489: LGTM! Test changes improve transaction handling.

The changes properly handle transactions and ensure proper cleanup of resources while maintaining test coverage.

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.

1 participant