Skip to content

fix: Modify mapper #209

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 90 commits into from
Apr 21, 2025
Merged

fix: Modify mapper #209

merged 90 commits into from
Apr 21, 2025

Conversation

lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented Apr 21, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor
    • Simplified conditional checks in various data filters and update operations by removing unnecessary empty string validations for boolean and flag fields. Now, these fields are included in queries and updates based solely on non-null values, improving consistency and maintainability. No changes to user-facing functionality or public interfaces.

lu-yg and others added 30 commits December 26, 2024 00:15
Copy link

coderabbitai bot commented Apr 21, 2025

Walkthrough

The changes across multiple MyBatis XML mapper files simplify conditional checks for various boolean or flag fields. Previously, these conditions tested for both non-nullity and non-empty string values (e.g., field != null and field != ''). The updates remove the redundant empty string checks, so the conditions now only verify that the fields are not null. This adjustment affects both query condition fragments and update set columns for each mapper, standardizing the logic for handling these fields. No changes were made to exported or public entity declarations, and the overall control flow remains unchanged.

Changes

File(s) Change Summary
AppMapper.xml, PageMapper.xml, PageHistoryMapper.xml, PlatformMapper.xml, Removed redundant empty string checks (!='') from conditional tests for boolean/flag fields; now only checks !=null
PageTemplateMapper.xml, MaterialMapper.xml, ComponentLibraryMapper.xml, in both query condition and update set column fragments.
ComponentMapper.xml, BlockMapper.xml, BlockHistoryMapper.xml, UserMapper.xml

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Mapper
    participant Database

    Client->>Mapper: Submit query/update with parameters
    Mapper->>Mapper: Check if field != null
    alt Field is not null
        Mapper->>Database: Include field in SQL WHERE/SET clause
    else Field is null
        Mapper->>Database: Exclude field from SQL clause
    end
    Database-->>Mapper: Return results/status
    Mapper-->>Client: Return results/status
Loading

Poem

In mapper fields where checks once grew,
Now only nullness guides us through.
No more empty strings to see,
Just clean and simple, as code should be!
The SQL hops with lighter feet,
Thanks to this tidy, bunny treat.
🐇✨

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.

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

@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)
base/src/main/resources/mappers/ComponentMapper.xml (1)

75-83: Ensure query conditions are consistent
The corresponding <if> tests in ComponentByCondition still include and isOfficial!='', and isDefault!='', and and isTinyReserved!=''. Consider removing these redundant empty‐string checks for consistency across your mapper.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3bc917 and 2265f07.

📒 Files selected for processing (11)
  • base/src/main/resources/mappers/AppMapper.xml (5 hunks)
  • base/src/main/resources/mappers/BlockHistoryMapper.xml (2 hunks)
  • base/src/main/resources/mappers/BlockMapper.xml (2 hunks)
  • base/src/main/resources/mappers/ComponentLibraryMapper.xml (2 hunks)
  • base/src/main/resources/mappers/ComponentMapper.xml (1 hunks)
  • base/src/main/resources/mappers/MaterialMapper.xml (4 hunks)
  • base/src/main/resources/mappers/PageHistoryMapper.xml (4 hunks)
  • base/src/main/resources/mappers/PageMapper.xml (4 hunks)
  • base/src/main/resources/mappers/PageTemplateMapper.xml (4 hunks)
  • base/src/main/resources/mappers/PlatformMapper.xml (4 hunks)
  • base/src/main/resources/mappers/UserMapper.xml (4 hunks)
🔇 Additional comments (20)
base/src/main/resources/mappers/UserMapper.xml (1)

22-24: Simplify boolean flag condition checks
Removed redundant empty‐string (!='') comparisons for the flag fields (isEnable, isAdmin, isPublic) in both the UserByCondition and UserSetColumns SQL fragments. Conditions now only test for !=null, which aligns with the intended wrapper‐type semantics and eliminates unnecessary string checks.

Also applies to: 46-48, 49-51, 62-64, 87-89, 90-92

base/src/main/resources/mappers/AppMapper.xml (1)

85-87: Streamline boolean flag conditions in App mapper
Removed redundant empty‐string checks (!='') for boolean/flag fields (isDefault, canAssociate, isPublish, isDemo) across the AppByCondition and AppSetColumns fragments. Now each <if> only verifies !=null, standardizing logic and reducing unnecessary evaluations.

Also applies to: 115-117, 176-178, 209-210, 212-214, 242-244

base/src/main/resources/mappers/BlockMapper.xml (1)

57-59: Simplify block‐flag null checks
Dropped redundant !='' checks for the flag parameters (isOfficial, isDefault, isTinyReserved) in both BlockByCondition and BlockSetColumns. Conditions now only test for non‐nullity, aligning with typed boolean semantics and improving readability.

Also applies to: 63-68, 148-150, 154-159

base/src/main/resources/mappers/BlockHistoryMapper.xml (1)

56-58: Remove unnecessary empty‐string tests for history flags
Consolidated the <if> tests for isOfficial, isDefault, and isTinyReserved by removing !='' checks in both the condition (BlockHistoryByCondition) and update (BlockHistorySetColumns) fragments. Now they only validate !=null, matching the field definitions and simplifying the SQL.

Also applies to: 62-67, 150-152, 156-161

base/src/main/resources/mappers/ComponentLibraryMapper.xml (1)

52-60: Streamline component‐library flag checks
Removed redundant empty‐string validations (!='') for the boolean/flag fields (isStarted, isOfficial, isDefault) in both the ComponentLibraryByCondition and ComponentLibrarySetColumns fragments. Conditions now solely check !=null, which is appropriate for wrapper‐type parameters and cleans up the SQL mappings.

Also applies to: 122-130

base/src/main/resources/mappers/ComponentMapper.xml (1)

172-180: Remove redundant empty-string checks for boolean flags in update fragment
The <if> conditions for isOfficial, isDefault, and isTinyReserved now correctly only test for non-null values, which is sufficient for boolean/flag fields.

base/src/main/resources/mappers/PageTemplateMapper.xml (2)

25-30: Simplify boolean flag checks in query fragment
The <if> tests for published, publicStatus, and isPreset now only verify != null, which is appropriate for nullable boolean/flag fields.

Also applies to: 37-39


83-88: Simplify boolean flag checks in update fragment
The <if> tests for published, publicStatus, and isPreset have been correctly updated to only check for non-null values in PageTemplateSetColumns.

Also applies to: 95-97

base/src/main/resources/mappers/PlatformMapper.xml (2)

21-23: Standardize null-only checks for boolean flags in query fragment
Removed redundant !='' checks for isPublish and isDefault, leaving only != null, which aligns with handling boolean fields.

Also applies to: 48-50


103-105: Standardize null-only checks for boolean flags in update fragment
Updated <if> tests for isPublish and isDefault to only test for non-null values in PlatformSetColumns, matching the query fragment changes.

Also applies to: 130-132

base/src/main/resources/mappers/PageHistoryMapper.xml (2)

34-36: Remove redundant empty-string checks for flag fields in query fragment
The <if> conditions for isBody, isPage, and isDefault now only test for non-null, which is correct for boolean/flag fields.

Also applies to: 46-48, 49-51


107-109: Remove redundant empty-string checks for flag fields in update fragment
The <if> tests for isBody, isPage, and isDefault have been simplified to only check for non-null values in PageHistorySetColumns.

Also applies to: 119-124

base/src/main/resources/mappers/MaterialMapper.xml (2)

33-35: Simplify null-only checks for boolean flags in query fragment
The <if> conditions for isPublish, isOfficial, isDefault, and isTinyReserved now correctly only test for non-null values, removing the redundant !='' checks.

Also applies to: 51-53, 54-56, 57-59


118-120: Simplify null-only checks for boolean flags in update fragment
Updated <if> tests for isPublish, isOfficial, isDefault, and isTinyReserved to only validate non-nullity in MaterialSetColumns, aligning with query fragment changes.

Also applies to: 136-138, 139-141, 142-144

base/src/main/resources/mappers/PageMapper.xml (6)

29-31: Simplify isBody condition
Removing the !='' check is correct for a Boolean/flag field—testing only isBody != null is sufficient and improves readability.


41-43: Simplify isPage condition
The empty‐string comparison was redundant for a Boolean-like field; retaining just isPage != null streamlines the SQL fragment without changing its behavior.


47-49: Simplify isDefault condition
Dropping the string‐emptiness check is appropriate, since isDefault represents a flag. The null check alone preserves correct filtering.


96-98: Simplify isBody update clause
In the <set> fragment, checking only isBody != null suffices for a Boolean field and makes the mapper more concise.


108-110: Simplify isPage update clause
Removing the !='' portion is valid; isPage != null alone correctly governs whether the column is included.


114-116: Simplify isDefault update clause
Testing isDefault != null by itself is sufficient for a flag field and reduces unnecessary complexity.

@lu-yg lu-yg merged commit 1e47ff8 into opentiny:develop Apr 21, 2025
1 check passed
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