-
Notifications
You must be signed in to change notification settings - Fork 1
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
π¨ Refactor/#34: Userμ μ¨κΈ° μ΄ νμ κ³μ° λ‘μ§μμ κ°κ²λ³ μ€λ³΅ μ κ±° #35
Conversation
WalkthroughThe changes involve modifications to the Changes
Assessment against linked issues
Poem
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? πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
π§Ή Outside diff range and nitpick comments (4)
src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java (1)
Line range hint
33-64
: Consider adding caching for performance optimization.Since the warmth count calculation involves multiple database queries and processing, consider implementing caching to improve performance. The count doesn't change frequently and could be invalidated only when new donations, receipts, or shares are added for the user.
Example implementation approach:
- Add a cache key based on user ID and last activity timestamp
- Cache the count result
- Invalidate cache when new activities are added
This would be particularly beneficial for users with a large number of activities.
src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java (3)
Line range hint
19-31
: Consider adding parameter validationWhile the builder pattern implementation is clean, consider adding null checks and empty list validation to ensure robust object creation.
public Onjung createOnjung( List<Donation> donations, List<Receipt> receipts, List<Share> shares ) { + if (donations == null || receipts == null || shares == null) { + throw new IllegalArgumentException("Lists cannot be null"); + } return Onjung.builder() .donations(donations) .receipts(receipts) .shares(shares) .build(); }
Line range hint
57-76
: Apply the same stream optimization as suggested for store countingThis method has the same structure and opportunities for optimization as the store counting method.
public Integer calculateTotalUniqueOnjungUserCount(Onjung onjung) { - Set<User> uniqueUsers = new HashSet<>(); - - // κ° λ¦¬μ€νΈμμ User κ°μ²΄λ₯Ό μμ§νμ¬ Setμ μΆκ° - uniqueUsers.addAll(onjung.getDonations().stream() - .map(Donation::getUser) - .collect(Collectors.toSet())); - - uniqueUsers.addAll(onjung.getReceipts().stream() - .map(Receipt::getUser) - .collect(Collectors.toSet())); - - uniqueUsers.addAll(onjung.getShares().stream() - .map(Share::getUser) - .collect(Collectors.toSet())); - - return uniqueUsers.size(); + return Stream.of( + onjung.getDonations().stream().map(Donation::getUser), + onjung.getReceipts().stream().map(Receipt::getUser), + onjung.getShares().stream().map(Share::getUser) + ) + .flatMap(Function.identity()) + .collect(Collectors.toSet()) + .size(); }
Line range hint
78-89
: Consider consistent stream usage patternThe method mixes different styles of calculation. Consider using a consistent stream-based approach for all three calculations.
public Integer calculateTotalOnjungAmount(Onjung onjung) { - return onjung.getDonations().stream() - .map(Donation::getDonationAmount) - .reduce(0, Integer::sum) + - onjung.getReceipts().stream() - .map(Receipt::getPaymentAmount) - .reduce(0, Integer::sum) + - onjung.getShares().size() * 100; + return Stream.of( + onjung.getDonations().stream().map(Donation::getDonationAmount).reduce(0, Integer::sum), + onjung.getReceipts().stream().map(Receipt::getPaymentAmount).reduce(0, Integer::sum), + onjung.getShares().stream().map(share -> 100).reduce(0, Integer::sum) + ).reduce(0, Integer::sum); }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
π Files selected for processing (3)
src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungBriefService.java
(1 hunks)src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java
(1 hunks)src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java
(3 hunks)
π Additional comments (5)
src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java (1)
57-58
: LGTM! The changes align well with the refactoring objective.
The modification correctly implements the new counting logic that excludes store duplicates, as intended by the PR objective. The updated comment clearly documents the behavior change.
Let's verify the implementation of the new counting method:
β Verification successful
Implementation correctly handles store uniqueness using HashSet β
The implementation in OnjungService
properly uses a HashSet
to eliminate store duplicates:
- Creates a
Set<Store>
to maintain unique stores - Collects stores from both donations and receipts using Stream API
- Automatically handles deduplication through HashSet's properties
The method is also being used consistently across the codebase:
ReadOnjungCountService
: For total unique store countReadOnjungBriefService
: As part of brief statistics
π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the implementation of calculateTotalUniqueOnjungStoreCount
# Expected: Method should use Set to ensure store uniqueness
# Search for the implementation
ast-grep --pattern 'calculateTotalUniqueOnjungStoreCount($$$) {
$$$
}'
# Verify test coverage
rg -A 5 "calculateTotalUniqueOnjungStoreCount.*test"
Length of output: 129
Script:
#!/bin/bash
# Let's try a different approach to find the implementation and tests
# Search for the method name in Java files
rg -t java "calculateTotalUniqueOnjungStoreCount" -B 2 -A 10
# Search for the class name to understand the context
rg -t java "class OnjungService" -B 2 -A 10
# Look for test files related to OnjungService
fd -e java -x grep -l "OnjungService.*Test"
Length of output: 5408
src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungBriefService.java (2)
55-56
: LGTM! The changes align well with the refactoring objectives.
The modification correctly implements the requirement to exclude store-based duplicates in the warmth calculation logic, as specified in issue #34.
55-56
: Verify the unique store counting implementation.
Let's ensure the new counting logic is implemented consistently across the codebase.
β Verification successful
Unique store counting implementation is correctly implemented
The new calculateTotalUniqueOnjungStoreCount
method is properly implemented using a HashSet to collect unique stores from donations, receipts, and shares. The method is consistently used across the codebase in ReadOnjungBriefService
and ReadOnjungCountService
, replacing the old calculateTotalOnjungCount
method where store uniqueness is required.
- The implementation correctly uses Java Streams to map and collect Store objects from all three sources
- Stores are properly deduplicated using HashSet's natural set properties
- The old counting method still exists but serves a different purpose (total actions count)
π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the implementation of unique store counting logic
# Check for any other occurrences of the old counting method
rg "calculateTotalOnjungCount" -A 2
# Check the implementation of the new counting method
ast-grep --pattern 'calculateTotalUniqueOnjungStoreCount($$$)'
# Look for similar counting logic in test files
fd -e java -e kt --full-path ".*[Tt]est.*" --exec rg "calculateTotal.*Count"
Length of output: 938
Script:
#!/bin/bash
# Let's check the implementation of the new unique store counting method
rg "calculateTotalUniqueOnjungStoreCount" -A 5
# Check for any store-related counting logic
rg "store.*count|count.*store" -i
# Look for test coverage of the new counting method
fd -e java --full-path ".*test.*" --exec rg "calculateTotalUniqueOnjungStoreCount"
# Check the Onjung class to understand the data structure
ast-grep --pattern 'class Onjung {
$$$
}'
Length of output: 4361
Script:
#!/bin/bash
# Let's check the complete implementation of OnjungService to see both old and new counting methods
rg -A 20 "class OnjungService" src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java
# Check the Onjung class's structure to understand donations, receipts, and shares
rg "getDonations|getReceipts|getShares" -A 2
# Look for any test files related to OnjungService
fd -e java --full-path ".*OnjungService.*Test.*"
Length of output: 4296
src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java (2)
Line range hint 3-14
: LGTM! Clean import organization
The imports are well-organized and include all necessary dependencies for the service functionality.
32-35
: Verify if this method is still needed
Given the PR's objective to focus on unique store counts and the introduction of calculateTotalUniqueOnjungStoreCount
, verify if this total count method is still needed in the codebase.
β Verification successful
Let me check the context of where this method is being used to better understand its purpose.
Let me check if there's a new unique count method being used in the same service to understand if both methods serve different purposes.
Let me check the complete implementation of ReadOnjungSummaryService to understand how both counts are being used.
The calculateTotalOnjungCount
method is still needed and serves a different purpose
The method is actively used in ReadOnjungSummaryService
to calculate the total number of donations (totalDonationCount
) which is different from unique store counts. While calculateTotalOnjungCount
counts all donations/receipts/shares, the unique count methods serve a different purpose by counting distinct entities. Both metrics are needed for different aspects of the summary response.
π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for usages of calculateTotalOnjungCount
rg "calculateTotalOnjungCount" -A 2
Length of output: 794
Script:
#!/bin/bash
# Get more context around the usage in ReadOnjungSummaryService
rg "class ReadOnjungSummaryService" -A 20
Length of output: 2601
Script:
#!/bin/bash
# Search for unique count method usage in ReadOnjungSummaryService
rg "calculateTotalUniqueOnjungStoreCount|calculateUnique" src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungSummaryService.java -A 2
Length of output: 151
Script:
#!/bin/bash
# Get the full implementation of ReadOnjungSummaryService
cat src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungSummaryService.java
Length of output: 2287
// μ¨μ κ°μ²΄λ₯Ό λ°μμ μ΄ μ¨μ νμλ₯Ό κ³μ°(κ°κ² μ€λ³΅ μ μΈ) | ||
public Integer calculateTotalUniqueOnjungStoreCount(Onjung onjung) { | ||
Set<Store> uniqueStores = new HashSet<>(); | ||
|
||
// κ° λ¦¬μ€νΈμμ Store κ°μ²΄λ₯Ό μμ§νμ¬ Setμ μΆκ° | ||
uniqueStores.addAll(onjung.getDonations().stream() | ||
.map(Donation::getStore) | ||
.collect(Collectors.toSet())); | ||
|
||
uniqueStores.addAll(onjung.getReceipts().stream() | ||
.map(Receipt::getStore) | ||
.collect(Collectors.toSet())); | ||
|
||
uniqueStores.addAll(onjung.getShares().stream() | ||
.map(Share::getStore) | ||
.collect(Collectors.toSet())); | ||
|
||
return uniqueStores.size(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Optimize stream operations and reduce duplication
While the implementation correctly handles store uniqueness, it can be optimized by combining the streams and reducing code duplication.
public Integer calculateTotalUniqueOnjungStoreCount(Onjung onjung) {
- Set<Store> uniqueStores = new HashSet<>();
-
- // κ° λ¦¬μ€νΈμμ Store κ°μ²΄λ₯Ό μμ§νμ¬ Setμ μΆκ°
- uniqueStores.addAll(onjung.getDonations().stream()
- .map(Donation::getStore)
- .collect(Collectors.toSet()));
-
- uniqueStores.addAll(onjung.getReceipts().stream()
- .map(Receipt::getStore)
- .collect(Collectors.toSet()));
-
- uniqueStores.addAll(onjung.getShares().stream()
- .map(Share::getStore)
- .collect(Collectors.toSet()));
-
- return uniqueStores.size();
+ return Stream.of(
+ onjung.getDonations().stream().map(Donation::getStore),
+ onjung.getReceipts().stream().map(Receipt::getStore),
+ onjung.getShares().stream().map(Share::getStore)
+ )
+ .flatMap(Function.identity())
+ .collect(Collectors.toSet())
+ .size();
}
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// μ¨μ κ°μ²΄λ₯Ό λ°μμ μ΄ μ¨μ νμλ₯Ό κ³μ°(κ°κ² μ€λ³΅ μ μΈ) | |
public Integer calculateTotalUniqueOnjungStoreCount(Onjung onjung) { | |
Set<Store> uniqueStores = new HashSet<>(); | |
// κ° λ¦¬μ€νΈμμ Store κ°μ²΄λ₯Ό μμ§νμ¬ Setμ μΆκ° | |
uniqueStores.addAll(onjung.getDonations().stream() | |
.map(Donation::getStore) | |
.collect(Collectors.toSet())); | |
uniqueStores.addAll(onjung.getReceipts().stream() | |
.map(Receipt::getStore) | |
.collect(Collectors.toSet())); | |
uniqueStores.addAll(onjung.getShares().stream() | |
.map(Share::getStore) | |
.collect(Collectors.toSet())); | |
return uniqueStores.size(); | |
} | |
// μ¨μ κ°μ²΄λ₯Ό λ°μμ μ΄ μ¨μ νμλ₯Ό κ³μ°(κ°κ² μ€λ³΅ μ μΈ) | |
public Integer calculateTotalUniqueOnjungStoreCount(Onjung onjung) { | |
return Stream.of( | |
onjung.getDonations().stream().map(Donation::getStore), | |
onjung.getReceipts().stream().map(Receipt::getStore), | |
onjung.getShares().stream().map(Share::getStore) | |
) | |
.flatMap(Function.identity()) | |
.collect(Collectors.toSet()) | |
.size(); | |
} |
Related issue π
closed #34
μ΄λ€ λ³κ²½μ¬νμ΄ μμλμ?
CheckPoint β
PRμ΄ λ€μ μꡬ μ¬νμ μΆ©μ‘±νλμ§ νμΈνμΈμ.
Work Description βοΈ
Uncompleted Tasks π
N/A
To Reviewers π’
Summary by CodeRabbit
New Features
Bug Fixes
Documentation