Repository navigation
perf: count a guild's nodes once per upkeep total - #29
Conversation
NodeManager.getTotalUpkeep(g) asked every node of g for its daily upkeep, and each node worked out its cost increase by counting g's nodes through a walk of every node: another nodes x nodes guild lookup, run whenever a ledger reads node upkeep (SimpleFactions income and the 5-minute chronicle export on Main). getTotalUpkeep now counts g's nodes once and passes the count to the new Node.getDailyUpkeep(int), which uses the same cost formula. Every node it adds belongs to g, so the count is the one each node would have found. getDailyUpkeep() keeps working on its own for single-node callers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The full build caught NodeUpkeepTest: getTotalUpkeep counted g's nodes before the loop, even when no node of g needed the count, and getDailyUpkeep(int) always used the counted cost increase. The old per-node path used the node's stored cost increase when its guild does not resolve and only counted for nodes that reached it. Node.getDailyUpkeep(IntSupplier) now falls back to getDailyUpkeep() when the guild does not resolve, and getTotalUpkeep passes a memoised count that walks the nodes at most once, on first use. NodeUpkeepTest passes unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sol review: the counted upkeep evaluated the node count before turning the base upkeep into a BigDecimal, so a bad upkeep value (NaN) with a failing count would surface a different exception than before. Both upkeep methods now take the base first, then resolve the guild, then count, which is the old order, and the unresolved fallback uses the stored cost increase directly so the guild is resolved once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@coderabbitai review |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
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 |
|
|
CodeRabbit is rate limited; Sol (GPT-6.1) approved after three rounds (final: 89cf740, no findings; exact evaluation order and exceptions preserved). CI green. Merging. |
Why
NodeManager.getTotalUpkeep(g)asked every node ofgfor its daily upkeep. Each node worked out its cost increase by countingg's nodes, which walks every node and resolves its guild, so a guild total cost nodes × nodes guild lookups. It runs whenever a ledger reads node upkeep: SimpleFactions income, and the 5-minute chronicle export on Main (10-28 spark profile zZVrBKel7T).Change
getTotalUpkeeppasses a memoised count to the newNode.getDailyUpkeep(IntSupplier). The guild's nodes are counted at most once, and only when a node first needs the count.getDailyUpkeep(IntSupplier)followsgetDailyUpkeep()step for step, so results, rounding and exceptions are the same:getDailyUpkeep()is unchanged for single-node callers. The two sharebaseUpkeep(),dailyUpkeep(..)andstoredCostIncrease().Testing
NodeUpkeepTestpasses unchanged.NodeBehaviorTestchecks on real nodes thatgetDailyUpkeep()equalsgetDailyUpkeep(() -> count), plus a counted value.main(DatabaseTest,NodePaymentsTest); the changed lines are covered.🤖 Generated with Claude Code