fix(server): persist inventory changes outside the close event - #648
Merged
Merged
Conversation
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
Inventory persistence had three gaps:
server/main.lua:210).anything mutated without being opened and closed was never persisted at all.
onResourceStopdid no saving, so arestart qb-inventorydiscarded in-memorystate for every inventory, including open ones.
This closes all three:
SaveInventoryItems(identifier)helper holds the upsert; the shutdown and closehandlers now call it instead of carrying their own copies of the SQL. This consolidates writes to one helper.
AddItemandRemoveItemwrite immediately when the target is anInventoriesentry that is not open, on the basis that an open inventory will get a close event
and be saved then; the at-risk mutations are exactly the ones to closed inventories.
onResourceStopflushes open inventories when qb-inventory itself stops.The resulting invariant: a closed inventory is always current in the database, and an
open one is written on close, on shutdown, or on resource stop. Only a hard crash
mid-session loses anything. Both existing handlers keep their
isOpenconditions,which are now sufficient rather than gaps.
Related issue
No issue. Found while working on #647; a headless
AddItemto a stash nobody had opened succeeded in memory with no persistence.Change type
Testing
AddItemto a closed stash, thenrestart qb-inventorywith no open orclose in between; item present afterwards. Previously lost.
restart qb-inventory; item present.Previously lost. This exercises the
onResourceStopflushSELECT identifier FROM inventories WHERE identifier LIKE 'drop-%'; empty, sodrops remain memory-only and no phantom rows are created.
/giveitemand a relog; player inventories unaffected.Compatibility and migration
None
Checklist
fix(scope): ...orfeat(scope): ....