Open GuySartorelli opened 11 months ago
The particular issue I had in the original ticket was not specifically that Member->write()
was called 3 times during login, but that we had a bunch of expensive API calls linked in onBeforeWrite()
or onAfterWrite()
.
The Member record was considered 'dirty' each time, which mean it went through the full ->write()
codepath every time and physically wrote changes to the DB, even though with two of those calls, nothing on the record actually changed. I dunno how that affects the onBefore
/onAfter
calls - but yeah, thought that extra info might help.
Prior to this patch,
Member->afterMemberLoggedIn()
did the following things:registerSuccessfulLogin()
which called->write()
regenerateTempID()
which called->write()
->write()
itselfThis means that every time a
Member
is considered 'logged in', the member ends up being written to the database 3 times, when only once is necessary.This wouldn't normally be a particular problem as it normally only happens explicitly when a member logs in via the login form (or at worst, on some random page via the auto-login cookie). However for a site that is protected by Basic Auth (e.g. with
BasicAuthMiddleware
), every single page loads re-authenticates theMember
and therefore requires 3 additional writes.Options
registerSuccessfulLogin()
andregenerateTempID()
not callwrite()
. Developers will need to explicitly callwrite()
after these methods, which allows them to also make additional changes after calling those methods before writing to the DB.write()
or not (as per the example PR)Example PR (option 2)