Refactor StallUpgradeManager for efficiency and simplicity#128
Conversation
- Introduced ConcurrentHashMap for caching calculated stat values. - Replaced iterative loop with fold operation in calculateValue. - Cleaned up redundant imports and fixed compilation errors in MainViewModel. - Updated fixes.md to record the refactoring. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR refactors the stall upgrade calculation system to use canonicalized stat names and caching, introduces a ChangesStall Upgrade System Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/src/main/java/com/messark/hawker/utils/StallUpgradeManager.kt (1)
129-177:⚠️ Potential issue | 🟠 Major | ⚡ Quick winCanonicalize all persisted stat metadata before recomputing upgrades.
This block only merges the Uncle aliases. Bak Kut Teh can still carry
"Damage"metadata, but Line 165 recomputes its level from"Boost"only, so that saved boost level drops back to base on the next upgrade/copy.namingCategorieshas the same inconsistency because it still stores rawstatName, which can let one logical stat count twice under mixed aliases.Proposed fix
- // Normalize aliases - listOf("Grab Rate", "Cleaning Time").forEach { alias -> - val canonical = getCanonicalStat(alias) - val level = max(mutableUpgrades.getOrDefault(alias, 0), mutableUpgrades.getOrDefault(canonical, 0)) + // Normalize aliases before reading levels or legendary categories. + val aliasPairs = buildList { + add("Grab Rate" to "Rate") + add("Cleaning Time" to "Duration") + if (stall.stallType == StallType.BAK_KUT_TEH) add("Damage" to "Boost") + } + aliasPairs.forEach { (alias, canonical) -> + val level = max( + mutableUpgrades.getOrDefault(alias, 0), + mutableUpgrades.getOrDefault(canonical, 0) + ) if (level > 0) { mutableUpgrades[alias] = level mutableUpgrades[canonical] = level } } @@ - val newNamingCategories = stall.namingCategories.toMutableList() + val newNamingCategories = stall.namingCategories + .map { + if (stall.stallType == StallType.BAK_KUT_TEH && it == "Damage") "Boost" + else getCanonicalStat(it) + } + .toMutableList() @@ - if (newLevelForStat == 10 && !stall.namingCategories.contains(statName)) { + if (newLevelForStat == 10 && !newNamingCategories.contains(canonicalStat)) { val legendaryCat = canonicalStat - if (stall.namingCategories.isEmpty()) { + if (newNamingCategories.isEmpty()) { newSuffix = LegendaryNames.getRandomSuffix(legendaryCat) - newNamingCategories.add(statName) + newNamingCategories.add(canonicalStat) } else if (stall.namingCategories.size == 1) { newPrefix = LegendaryNames.getRandomPrefix(legendaryCat) - newNamingCategories.add(statName) + newNamingCategories.add(canonicalStat) } }As per coding guidelines,
Use StallUpgradeManager to normalize stat aliasing mappings (e.g., 'Grab Rate' → 'Rate') upfront to prevent state-resetting bugs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8743c2c0-2159-4eb8-864e-9c8bbf815062
📒 Files selected for processing (4)
app/src/main/java/com/messark/hawker/MainViewModel.ktapp/src/main/java/com/messark/hawker/utils/GridUtils.ktapp/src/main/java/com/messark/hawker/utils/StallUpgradeManager.ktfixes.md
💤 Files with no reviewable changes (1)
- app/src/main/java/com/messark/hawker/utils/GridUtils.kt
|
stall has type Stall? (from tile?.stall). The condition stall?.stallType == StallType.BAK_KUT_TEH uses a safe-call equality, which does not trigger Kotlin smart cast. As a result, both stall.disabledWaves (line 1223) and stall.damage (line 1224) are non-null member accesses on a nullable type, causing a compile error. Add an explicit stall != null guard to enable smart cast for subsequent accesses Also Canonicalize all persisted stat metadata before recomputing upgrades. This block only merges the Uncle aliases. Bak Kut Teh can still carry "Damage" metadata, but Line 165 recomputes its level from "Boost" only, so that saved boost level drops back to base on the next upgrade/copy. namingCategories has the same inconsistency because it still stores raw statName, which can let one logical stat count twice under mixed aliases. |
I've implemented the requested changes:
|
- Fixed compile error in calculateStatBoost with explicit null guard. - Generalized stat normalization and canonicalization in StallUpgradeManager. - Fixed inconsistent namingCategories logic by using canonical stat names. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
This PR refactors the stat calculation logic in StallUpgradeManager.kt. The previous O(level) iterative loop has been replaced with an idiomatic Kotlin fold operation, and a thread-safe ConcurrentHashMap has been introduced to cache calculated values, significantly improving performance for repeated stat lookups. Redundant imports and unrelated compilation issues in GridUtils and MainViewModel have also been resolved.
PR created automatically by Jules for task 7076087423520579259 started by @candour
Summary by CodeRabbit
Performance Improvements
Enhancements
Bug Fixes