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

optimize: clarify if conditions #6442

Merged
merged 5 commits into from
Apr 8, 2024
Merged

Conversation

YeonCheolGit
Copy link
Contributor

@YeonCheolGit YeonCheolGit commented Mar 23, 2024

Ⅰ. Describe what this PR did

(please see each commit)

  • Changed to clarify the If condition that does various things
  • Change the English grammar of comments to be more natural

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

It has already tese cases.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@YeonCheolGit YeonCheolGit changed the title refactor: clarify if condition refactor: clarify if conditions Mar 23, 2024
@1150456356
Copy link

good

@YeonCheolGit
Copy link
Contributor Author

cc. @funky-eyes


// The entire undo process should run in a local transaction.
if (originalAutoCommit = conn.getAutoCommit()) {
if (conn.getAutoCommit()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand the purpose of doing this. Here, conn.getAutoCommit() is used twice.

Copy link
Contributor Author

@YeonCheolGit YeonCheolGit Mar 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slievrly Thank you for the review.

I intended to divdie assign to variable and check whether is true or not in If condtion for clarify. conn.getAutoCommit() returns only state so i assumed will be okay for using twice.

What about these alternatively?

originalAutoCommit = conn.getAutoCommit();
if (originalAutoCommit)

or

final boolean autoCommitState = conn.getAutoCommit();
originalAutoCommit = autoCommitState
if (autoCommitState)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the first expression for its simplicity and fidelity to the original meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review!
I've addressed your comments and pushed a new commit with the changes 😄

@slievrly slievrly changed the title refactor: clarify if conditions optimize: clarify if conditions Mar 25, 2024
@slievrly
Copy link
Member

Additionally, remember to update the change log. This PR falls under the category of optimization.

@xingfudeshi xingfudeshi added the first-time contributor first-time contributor label Mar 26, 2024
This if condition seems to have three pieces of logic:
1. Check if conn.getAutoCommit() is true.
2. Assign conn.getAutoCommit() to originalAutoCommit.
3. If conn.getAutoCommit() is true, then set conn.setAutoCommit(true).

However, the if condition is assigning originalAutoCommit from conn.getAutoCommit() and checking whether conn.getAutoCommit() is true or false simultaneously.

clarify and divide the logic
This if condition seems to have three pieces of logic:
1. Acquire a distributed lock with a key.
2. Assign the acquired distributed lock to the 'lock' variable.
3. If the lock is successfully acquired, then make a function call.

However, the if condition is doing two jobs simultaneously, which makes it unclear.

divide and clarify the logic.
@YeonCheolGit
Copy link
Contributor Author

Additionally, remember to update the change log. This PR falls under the category of optimization.

I changed commit message from 'refactor' to 'optimize'. Thanks for the review :)

@codecov-commenter
Copy link

codecov-commenter commented Mar 30, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 50.85%. Comparing base (a24a43e) to head (ec35f20).

❗ Current head ec35f20 differs from pull request most recent head a57e13f. Consider uploading reports for the commit a57e13f to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6442      +/-   ##
============================================
+ Coverage     50.26%   50.85%   +0.59%     
- Complexity     5242     5286      +44     
============================================
  Files           942      942              
  Lines         33270    33273       +3     
  Branches       4030     4030              
============================================
+ Hits          16722    16922     +200     
+ Misses        14929    14685     -244     
- Partials       1619     1666      +47     
Files Coverage Δ
...ver/storage/redis/lock/RedisDistributedLocker.java 59.09% <ø> (-13.64%) ⬇️
...ata/rm/datasource/undo/AbstractUndoLogManager.java 53.15% <50.00%> (+0.24%) ⬆️
...org/apache/seata/server/session/SessionHolder.java 52.44% <50.00%> (+0.33%) ⬆️
...a/server/storage/db/lock/LockStoreDataBaseDAO.java 50.48% <50.00%> (+0.24%) ⬆️

... and 43 files with indirect coverage changes

@YeonCheolGit
Copy link
Contributor Author

YeonCheolGit commented Apr 5, 2024

@xingfudeshi
Copy link
Member

You should update the changes file in this PR without creating a separate PR.

@YeonCheolGit
Copy link
Contributor Author

You should update the changes file in this PR without creating a separate PR.

Oh i misunderstanded. Add commit in this PR.

Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xingfudeshi xingfudeshi merged commit 77bcaa2 into apache:2.x Apr 8, 2024
6 checks passed
@@ -115,6 +115,11 @@
- [[#6387](https://github.com/apache/incubator-seata/pull/6387)] 优化tcc使用兼容
- [[#6402](https://github.com/apache/incubator-seata/pull/6402)] 优化rm-datasource向下兼容
- [[#6419](https://github.com/apache/incubator-seata/pull/6419)] 优化integration-tx-api向下兼容
- [[#6442](https://github.com/apache/incubator-seata/pull/6442)] 阐明 if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change log look there are some problems.

@slievrly slievrly added this to the 2.1.0 milestone Apr 29, 2024
@YeonCheolGit YeonCheolGit deleted the yeoncheol/2.x branch May 5, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-time contributor first-time contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants