Skip to content

Stop persisting Spellups on every checkExist call#100

Open
rodarvus wants to merge 1 commit into
zzyzzyzzx:masterfrom
rodarvus:fix/checkexist-stop-per-key-save
Open

Stop persisting Spellups on every checkExist call#100
rodarvus wants to merge 1 commit into
zzyzzyzzx:masterfrom
rodarvus:fix/checkexist-stop-per-key-save

Conversation

@rodarvus

Copy link
Copy Markdown

Summary

checkExist() in SpellupRecast/Hadar_Spellups.xml ensures a key exists in the Spellups table and was also calling SetVariable("Spellups", serialize.save("Spellups")) every time it added a missing key. Because injectVars() calls checkExist dozens of times in sequence on startup, the full Spellups table was being serialized and written to plugin state once per key — measurable I/O churn for no benefit on a fresh install or version bump.

This drops the SetVariable call. OnPluginSaveState already persists Spellups (via serialize.save_simple) at shutdown, plugin disable, and the standard MUSHclient save points, so the data still reaches disk — just once, at the right time.

As a side effect this also removes the only call to serialize.save("Spellups") (the name-based variant), leaving serialize.save_simple as the single writer. That matches what the loadstring reader in OnPluginEnable already expects, so the read/write paths are now consistent.

The over-indented assignment inside the if branch is also tidied.

Before

function checkExist(tbl, idx, val) 

     if not Spellups[tbl] then
          Spellups[tbl] = {}
     end

     if not Spellups[tbl][idx] then
               Spellups[tbl][idx] = val
               SetVariable("Spellups", serialize.save("Spellups")) 
     end
     
end

After

function checkExist(tbl, idx, val)

     if not Spellups[tbl] then
          Spellups[tbl] = {}
     end

     if not Spellups[tbl][idx] then
          Spellups[tbl][idx] = val
     end
end

Test plan

  • Static — confirmed OnPluginSaveState (line 544) is the canonical writer; checkExist's SetVariable was redundant.
  • No normal-flow behavior change — keys are still ensured to exist; persistence still happens, just at the right granularity.

🤖 Generated with Claude Code

checkExist() ensures a key exists in the Spellups table and was also
calling SetVariable("Spellups", serialize.save("Spellups")) every
time it added a missing key. injectVars() calls checkExist dozens of
times in a row on startup, so the full table was being serialized
and written to state once per key.

Drop the SetVariable call -- OnPluginSaveState already persists
Spellups (via serialize.save_simple) at shutdown, plugin disable,
and the normal MUSHclient save points. As a side effect this also
removes the only call to serialize.save("Spellups") (the name-based
variant), leaving serialize.save_simple as the single writer, which
matches what the loadstring on the read path expects.

Also tidies the over-indented assignment inside the if-branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <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