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

solve the problem of duplicate comments and blank lines #5232

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

Conversation

youngzil
Copy link
Contributor

@youngzil youngzil commented Sep 19, 2024

  1. solve the problem of duplicate comments and blank lines
  2. reduce the data growth of the item table
  3. in the same case, the size of ItemChangeSets can be reduced
  4. when revoke configuration, if there is only one comment or blank line, it will not be deleted.

What's the purpose of this PR

XXXXX

Which issue(s) this PR fixes:

Fixes #5000

Brief changelog

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

  • New Features

    • Enhanced handling of comment and blank items for improved processing efficiency.
    • Streamlined logic for managing deleted items, ensuring only valid entries are processed.
  • Bug Fixes

    • Adjusted test assertions to reflect changes in item resolution logic, improving accuracy in handling item states.
  • Refactor

    • Simplified code structure for better maintainability and clarity in various methods related to item management.

1. solve the problem of duplicate comments and blank lines
2. reduce the data growth of the item table
3. in the same case, the size of ItemChangeSets can be reduced
4. when revoke configuration, if there is only one comment or blank line, it will not be deleted.
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 19, 2024
Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes primarily involve enhancing the handling of comment and blank items in the PropertyResolver class, improving the logic for deleted items in the ItemService and NamespaceService classes, and updating corresponding test cases. The modifications streamline the processing of items, eliminate reliance on outdated structures, and ensure that only valid items are considered during operations. Overall, the updates focus on improving code clarity, efficiency, and correctness in item management.

Changes

File Change Summary
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java Enhanced handling of comment and blank items; replaced old line number map with lists; refactored methods for clarity and efficiency.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java Improved logic for handling deleted items in revokeItem method by filtering out items with empty keys and simplifying item addition to changeSets.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java Refined handling of deleted items in transformNamespace2BO method by using streams; ensured valid entries in newItemMap.
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolverTest.java Updated assertions in tests to reflect changes in item resolution logic, adjusting expected counts for delete, update, and create items.

Assessment against linked issues

Objective Addressed Explanation
Ensure no automatic addition of duplicate comments after undoing changes (#5000)

🐰 In the meadow, changes bloom,
Comments tidy, no more gloom.
Items handled with great care,
No duplicates lurking, everywhere!
Code now dances, clear and bright,
A hop of joy, all feels just right! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 31e6486 and 1c7dcf8.

Files selected for processing (4)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java (6 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java (3 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java (2 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolverTest.java (2 hunks)
Additional comments not posted (21)
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolverTest.java (3)

94-96: LGTM!

The updated assertions in the testDeleteCommentItem method align with the expected behavior of deleting comment items based on the PR objectives. The changes correctly verify that:

  • 1 item is deleted (the comment item)
  • 3 items are updated (the remaining key-value pairs and blank line)
  • 0 items are created

123-125: LGTM!

The updated assertions in the testUpdateCommentItem method align with the expected behavior of updating comment items based on the PR objectives. The changes correctly verify that:

  • 0 items are deleted
  • 1 item is updated (the comment item)
  • 0 items are created

131-133: LGTM!

The updated assertions in the testAllSituation method align with the expected behavior of resolving a configuration with various item types based on the PR objectives. The changes correctly verify that:

  • 0 items are deleted
  • 4 items are updated (the existing key-value pairs, blank line, and comment line)
  • 3 items are created (the new key-value pairs and comment line)

These assertions reflect the PR's goals of handling duplicate comments and blank lines, and minimizing data growth in the item table.

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java (13)

24-24: LGTM!

The import statement is valid and does not introduce any issues.


27-27: LGTM!

The import statement is valid and does not introduce any issues.


30-31: LGTM!

The import statements are valid and do not introduce any issues.


37-37: LGTM!

The import statement is valid and does not introduce any issues.


57-66: LGTM!

The introduction of separate lists for comment and blank items is a good approach to simplify the processing logic. Filtering and sorting the baseItems list is an efficient way to populate the new lists. The code segment does not introduce any apparent issues.


83-86: LGTM!

The code segment correctly handles the case when baseCommentItems is empty. Removing the first item from baseCommentItems ensures that the list is processed in order. The code segment does not introduce any apparent issues.


88-88: LGTM!

The code segment correctly passes the oldItemDTO to the handleCommentLine method. The code segment does not introduce any apparent issues.


93-97: LGTM!

The code segment correctly handles the case when baseBlankItems is empty. Removing the first item from baseBlankItems ensures that the list is processed in order. The code segment does not introduce any apparent issues.


98-98: LGTM!

The code segment correctly passes the oldItemDTO to the handleBlankLine method. The code segment does not introduce any apparent issues.


108-108: LGTM!

The code segment correctly passes the remaining items in baseCommentItems and baseBlankItems to the deleteCommentAndBlankItem method. The code segment does not introduce any apparent issues.


147-150: LGTM!

The code segment correctly handles the case when oldItemByLine is null by adding a create item. It also correctly checks for changes in the comment or line number and adds an update item if necessary. The code segment does not introduce any apparent issues.


155-158: LGTM!

The code segment correctly handles the case when oldItem is null by adding a create item. It also correctly checks for changes in the line number and adds an update item if necessary. The code segment does not introduce any apparent issues.


210-214: LGTM!

The refactored deleteCommentAndBlankItem method is cleaner and more maintainable compared to the previous implementation. Directly iterating over the new lists removes the need for complex conditional checks. The code segment does not introduce any apparent issues.

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java (3)

220-221: Approved: Removal of comment and blank item map entries.

The removal of comment and blank item map entries ensures that only valid items are processed, preventing potential issues related to empty keys.


224-226: Improved item filtering using Java Streams.

The updated code leverages Java Streams to filter out items with empty keys before collecting them into a map. This approach not only improves the clarity of the code but also ensures that only valid items are processed, thereby preventing potential issues related to empty keys.


243-243: Simplified logic for adding deleted items to changeSets.

The logic for adding deleted items to changeSets has been simplified, enhancing readability and correctness. The revised implementation directly uses the value from the iteration, improving code clarity.

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java (2)

335-337: Approved: The changes improve code clarity and efficiency.

The updated code streamlines the process of creating and populating the deletedItemDTOs map by consolidating the logic into a single stream operation. This enhances code readability and efficiency.

Additionally, filtering out items with empty keys ensures that the map only contains valid entries, potentially preventing issues during further processing.


387-388: Approved: The changes ensure the map only contains valid entries.

The updated code removes entries with empty keys from the newItemMap before performing the comparison with releaseItems. This ensures that the newItemMap only contains valid entries, potentially preventing issues or unexpected behavior during the comparison process.


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

@youngzil
Copy link
Contributor Author

// TODO
code:com.ctrip.framework.apollo.portal.service.ItemService#revokeItem
Remaining issues:
When revoking a configuration, the number of configuration lines will be reset, which will cause confusion between the number of comments and configuration lines. This cannot be solved at present.

@youngzil
Copy link
Contributor Author

youngzil commented Sep 20, 2024

Using the test case in #5000, there is another problem
### Add a question about revoke configuration

  1. The initial configuration is as follows

image

  1. The second step only deletes the fourth line, and the comment on the third line is still retained.
  2. But when I revoke the configuration, I find that the comment on the third line is also deleted.

image

  1. The reasons why this happens are as follows:
    L218:oldKeyMapItem contains a comment or a blank line
    L241:The comment or blank line in oldKeyMapItem will be deleted.

So I removed this comment or blank line in #5232

https://github.com/apolloconfig/apollo/blob/31e6486791de3ad60f059f34957b343839aa5ebb/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java#L218C1-L219C1

oldKeyMapItem.forEach((key, value) -> changeSets.addDeleteItem(oldKeyMapItem.get(key)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Text配置修改,含有注释的情况下,撤销修改导致后续存在自动添加重复注释
1 participant