fix(server/accounts): return cached account instance in OxAccount.get - #253
Open
DoluTattoo wants to merge 1 commit into
Open
fix(server/accounts): return cached account instance in OxAccount.get#253DoluTattoo wants to merge 1 commit into
DoluTattoo wants to merge 1 commit into
Conversation
The cache lookup discarded its result instead of returning it, so every call fell through to SelectAccount and constructed a new OxAccount. The registry kept the first instance while callers received throwaway ones, and each lookup paid for a redundant query.
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.
Problem
OxAccount.getnever returns its cached instance:this.members[accountId]is an expression statement, so the looked-up value is discarded. Every call falls through toSelectAccountand constructs a newOxAccount, which makes the cache write-only — the eviction interval inserver/accounts/index.tshas nothing to evict that was ever read.Because
ClassInterface.addreturns early when the id is already registered, the registry keeps the very first instance while every later caller receives a throwaway one. The extra instances are not leaked, but each lookup pays for a redundantSELECT.Fix
Return the cached instance when one exists.
Behaviour
Identical, minus the redundant query:
DeleteAccountonly setstype = 'inactive'and never deletes the row, andSelectAccountdoes not filter ontype. So a cachedaccountIdalways still resolves in the database — theSELECTcould never turn a cache hit into theNo account existserror.OxAccountholds no mutable state beyondaccountId, so a cached instance is equivalent to a freshly constructed one.Impact
Minor. The wasted query is a primary-key lookup, so this is a correctness/hygiene fix rather than a performance emergency. Note that
GetCharacterAccountandGetGroupAccountstill runSelectDefaultAccountIdbeforehand, so only the second query is avoided on those paths.