Skip to content

fix(ledger.lic): v1.4.2 track Account.name for better loot_cap estima…#2318

Open
mrhoribu wants to merge 2 commits into
masterfrom
fix/ledger-v1.4.2
Open

fix(ledger.lic): v1.4.2 track Account.name for better loot_cap estima…#2318
mrhoribu wants to merge 2 commits into
masterfrom
fix/ledger-v1.4.2

Conversation

@mrhoribu
Copy link
Copy Markdown
Contributor

@mrhoribu mrhoribu commented May 11, 2026

…tion

Summary by CodeRabbit

  • New Features

    • Account-wide loot-cap estimation: loot-cap earnings now calculate across all your account's characters rather than per-character.
    • New account tracking system with automatic account name resolution.
  • Improvements

    • Terminal chart rendering refined with updated bar characters for improved visibility.
  • Chores

    • Version updated to 1.4.2.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

Warning

Rate limit exceeded

@mrhoribu has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 11 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63df464b-9dce-46d9-95f8-1663c543b14e

📥 Commits

Reviewing files that changed from the base of the PR and between 52d3d4e and 94a59d8.

📒 Files selected for processing (1)
  • scripts/ledger.lic
📝 Walkthrough

Walkthrough

Version 1.4.2 extends the ledger script with account-wide loot-cap estimation. A new AccountInfo module resolves account names, the database schema adds an account column and index for persistence, estimate_loot_cap queries now filter by account or fall back to character when unresolvable, transaction recording stores the account name, and chart rendering uses a simpler bar character.

Changes

Account-wide Ledger Tracking

Layer / File(s) Summary
Version and Changelog
scripts/ledger.lic
Version bumped from 1.4.1 to 1.4.2 with changelog entry describing account name tracking on transactions and account-wide loot-cap aggregation with proxy-mode fallback.
Account Resolution Infrastructure
scripts/ledger.lic
New Ledger::AccountInfo module with name method that returns Account.name if available or resolves it via in-game account command using Lich::Util.quiet_command_xml.
Database Schema and Migration
scripts/ledger.lic
Added account column to transactions table and created index on [:account, :type] to optimize account-wide loot-cap queries.
Account-wide Loot-cap Estimation
scripts/ledger.lic
Ledger::Character.estimate_loot_cap extended with account parameter (defaulting to AccountInfo.name), filtering transactions by account or falling back to character when account is nil/unresolvable.
Transaction Recording with Account Tracking
scripts/ledger.lic
Ledger::History.record_transaction now stores the resolved account name into transaction[:account] for newly recorded rows.
Chart Rendering Adjustment
scripts/ledger.lic
Hourly chart bar character changed from to | in Terminal::Table fallback rendering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • elanthia-online/scripts#2313: Both PRs enhance Ledger::Character.estimate_loot_cap with weekly loot-cap logic; this PR extends that to account-wide queries and adds account infrastructure and database support.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: tracking Account.name to improve loot_cap estimation in ledger.lic, which aligns with the raw summary showing account-wide loot-cap computation and AccountInfo module introduction.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ledger-v1.4.2

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/ledger.lic`:
- Around line 418-430: AccountInfo.name currently re-runs
Lich::Util.quiet_command_xml each time when Account.name is empty; memoize the
lookup (including the negative result) so the verb is sent at most once per
session: add a class-level cache (e.g., `@cached_account_name` and
`@cached_account_name_set`) used by AccountInfo.name to return a cached value if
set, only call Lich::Util.quiet_command_xml when the cache is unset, store
either the found name or nil into `@cached_account_name` and mark
`@cached_account_name_set`=true, and add an optional invalidation method (e.g.,
AccountInfo.invalidate_name_cache) so callers like record_transaction and
estimate_loot_cap will use the cached outcome and avoid repeated account
commands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c21f10d3-107d-4be4-8d45-f5d4f5ed66e4

📥 Commits

Reviewing files that changed from the base of the PR and between 74ab820 and 52d3d4e.

📒 Files selected for processing (1)
  • scripts/ledger.lic

Comment thread scripts/ledger.lic
Comment on lines +418 to +430
def self.name
return nil unless Object.const_defined?(:Account)
return Account.name if Account.name && !Account.name.to_s.empty?

begin
Lich::Util.quiet_command_xml("account", /Account Name:/i, /<prompt/, false, 3)
rescue StandardError => e
echo "AccountInfo: failed to resolve via ACCOUNT (#{e.message})"
return nil
end

Account.name if Account.name && !Account.name.to_s.empty?
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Memoize the unresolvable case to avoid repeated ACCOUNT commands on every transaction.

When Account.name is empty (e.g., proxy-mode logins, which the changelog explicitly calls out), this method falls through to quiet_command_xml("account", ...) and waits up to 3 seconds. Because record_transaction (line 611) calls AccountInfo.name on every recorded transaction, an unresolvable account will:

  1. Block the main History.main loop for ~3s per recorded transaction, risking missed/late deposit/withdraw matches that immediately follow.
  2. Spam the in-game account command (visible server-side) every time silver/bounty changes.

The same applies to the account: default on estimate_loot_cap (line 348), though that path is colder.

Cache the resolution outcome (including the negative case) so the verb is sent at most once per session, with an optional invalidation hook if needed.

🔒 Proposed fix: memoize the resolved/unresolvable state
   module AccountInfo
+    `@resolved`    = false
+    `@cached_name` = nil
+
+    # Reset the cached resolution; useful if the user runs ;account later
+    # in the session and we want to retry.
+    def self.reset!
+      `@resolved`    = false
+      `@cached_name` = nil
+    end
+
     # Returns the current account name, populating it via the ACCOUNT verb if
     # needed. Lich5 (Infomon) parses the ACCOUNT response and assigns
     # Account.name itself; we just trigger the round-trip and read it back.
     #
     # `@return` [String, nil] account name, or nil if it cannot be resolved
     def self.name
+      return `@cached_name` if `@resolved`
       return nil unless Object.const_defined?(:Account)
-      return Account.name if Account.name && !Account.name.to_s.empty?
+      if Account.name && !Account.name.to_s.empty?
+        `@resolved` = true
+        return `@cached_name` = Account.name
+      end
 
       begin
         Lich::Util.quiet_command_xml("account", /Account Name:/i, /<prompt/, false, 3)
       rescue StandardError => e
         echo "AccountInfo: failed to resolve via ACCOUNT (#{e.message})"
-        return nil
+        `@resolved` = true
+        return `@cached_name` = nil
       end
 
-      Account.name if Account.name && !Account.name.to_s.empty?
+      `@resolved` = true
+      `@cached_name` = (Account.name if Account.name && !Account.name.to_s.empty?)
     end
   end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/ledger.lic` around lines 418 - 430, AccountInfo.name currently
re-runs Lich::Util.quiet_command_xml each time when Account.name is empty;
memoize the lookup (including the negative result) so the verb is sent at most
once per session: add a class-level cache (e.g., `@cached_account_name` and
`@cached_account_name_set`) used by AccountInfo.name to return a cached value if
set, only call Lich::Util.quiet_command_xml when the cache is unset, store
either the found name or nil into `@cached_account_name` and mark
`@cached_account_name_set`=true, and add an optional invalidation method (e.g.,
AccountInfo.invalidate_name_cache) so callers like record_transaction and
estimate_loot_cap will use the cached outcome and avoid repeated account
commands.

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.

1 participant