Repository navigation
Conversation
Fixes JaylyDev#334. Before, when the database read the scoreboard, it assumed every entry returned by getParticipants() was valid. In some cases the game returns an empty (undefined) entry for an identity that was already removed, and the script crashed trying to read its type, which stopped the database from loading its data. Now those empty entries are skipped and the rest of the data loads normally.
Refs JaylyDev#311. Before, every open database re-read the whole scoreboard on every game tick (20 times per second), rebuilding its local copy each time. With large databases or several of them this used a lot of processing time and could slow the world down. Now the sync runs every 20 ticks, once per second, using the new SYNC_INTERVAL constant. Reads and writes made by the script are not affected, since they use the local copy directly. Only changes made to the scoreboard from outside the script (for example, with commands) may take up to one second to appear. The single full read done when the database is first created is unchanged, so this reduces the ongoing cost but may not remove the startup spike reported in the issue on its own.
Before, the two functions changed in this branch had an extra comment above them marking who made the correction. That note is not useful to the project and repeated what the inline comments already explain. Now only the inline comments that describe each fix (JaylyDev#334 and JaylyDev#311) remain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes two problems in
jaylydb. Each one is in its own commit so they can be reviewed separately.undefinedentries returned bygetParticipants()1. Crash on undefined participants (#334)
Problem.
updateParticipants()assumes every element fromobjective.getParticipants()is a validScoreboardIdentity. Sometimes the array containsundefinedfor an identity that has just been removed, and the loop then throws:This error happens inside the
runIntervalcallback. It interrupts the sync, so the database's local cache can be left cleared or incomplete. The reporter said the error is intermittent, which fits a short gap while an identity is being removed.Fix. Treat a missing participant like a non-fake-player entry and skip it:
2. Full scoreboard re-read on every tick (#311)
Problem. The
runIntervalin the constructor has no interval argument, so it runs on every tick, 20 times per second. On each run,updateParticipants()clears the local cache and parses every participant again. That cost grows with the size of the database and the number of databases, and you pay it on every tick even when nothing has changed.Fix. Add a
SYNC_INTERVALconstant (20 ticks = 1 second) and pass it tosystem.runInterval.Behavior impact:
get,set,delete, iteration and the other methods still use the local cache directly, so the script sees no change in behavior./scoreboardcommands) can now take up to one second to show up in the cache.SYNC_OKlogic) works as before. It now runs on the same one-second interval.Why "Refs" and not "Fixes". Issue #311 reports a watchdog spike while the database initializes. This change removes the repeated per-tick work. It does not change the single full read in the constructor, so a very large database may still cause a spike at startup. I'd rather leave the issue open for the maintainers to confirm. A follow-up could spread the initial load across several ticks, for example with
system.runJob.Testing
tsc --noEmit -p scriptspasses with no errors, checked after each commit.index.tsand the generatedindex.jsthe same way, so the two files stay in sync.