Skip to content

fix: run the entity scan after autoLoadCache so underlines appear on book open - #1

Open
tramch wants to merge 1 commit into
Dukko:mainfrom
tramch:fix/scan-after-autoloadcache
Open

tramch wants to merge 1 commit into
Dukko:mainfrom
tramch:fix/scan-after-autoloadcache

Conversation

@tramch

@tramch tramch commented Sep 11, 2026

Copy link
Copy Markdown

Problem

The initial entity scan runs from the XRayPlugin:init() hook, but at that point X-Ray's per-book tables are still the empty ones init() just assigned (self.characters = {} etc.). They're only restored from the sidecar in autoLoadCache(), which runs from onReaderReady after init.

So the init-hook scan collects 0 terms, takes the #terms == 0 branch and sets entity_xp_matches = {} — the "scanned, nothing to show" marker. Every later automatic call to ensureEntityFootnotesSetup then sees entity_xp_matches is non-nil and skips. Result: no underlines on book open; they only appear after a manual Scan/Rescan from the X-Ray menu. (On the very first book of a session the init hook doesn't fire at all, per the existing comment, so that case had no automatic scan either.)

Fix

Hook XRayPlugin:autoLoadCache and run the full setup once it returns, i.e. once characters/locations/historical_figures/terms are actually populated. Because the wrapper sits on the class table and onReaderReady happens after the patch has loaded, this also covers the first book of a session.

The init hook is kept for the localization/mount setup (harmless to do early) but now passes skip_scan = true so it can no longer poison entity_xp_matches before the tables exist.

Tested

Kindle Colorsoft, KOReader 2026.07.1, X-Ray 26.8.x and 26.9.10-beta3 — underlines now show on the first book after a KOReader start and on every subsequent open, and the sidecar entity cache is loaded instead of rescanned when the signature matches.

🤖 Generated with Claude Code

…book open

The initial scan was triggered from the XRayPlugin:init() hook, but at that
point X-Ray's per-book entity tables are still the empty ones init() just
assigned (self.characters = {} etc.). They are only restored from the sidecar
cache in autoLoadCache(), which runs from onReaderReady after init. So the
init-hook scan collected 0 terms, took the "#terms == 0" branch, and set
entity_xp_matches = {} -- the "scanned, nothing to show" marker -- which then
made every later automatic call to ensureEntityFootnotesSetup skip the scan.
Net effect: no underlines on book open; they only came back after a manual
Scan/Rescan from the X-Ray menu. On the very first book of a session the init
hook doesn't fire at all (see the existing comment above
ensureEntityFootnotesSetup), so that case had no automatic scan either.

Hook XRayPlugin:autoLoadCache instead and run the full setup once it returns,
i.e. once characters/locations/historical_figures/terms are actually
populated. This also covers the first book of a session, because the wrapper
sits on the class table and onReaderReady happens after the patch has run.

The init hook is kept for the localization/mount setup (harmless to do early)
but now passes skip_scan=true so it can no longer poison entity_xp_matches
before the tables exist.

Tested on Kindle Colorsoft, KOReader 2026.07.1, X-Ray 26.8.x and 26.9.10-beta3.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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