refactor(database): optimize groupGetType by caching it inside BaseBuilder loops#10340
refactor(database): optimize groupGetType by caching it inside BaseBuilder loops#10340gr8man wants to merge 1 commit into
Conversation
michalsn
left a comment
There was a problem hiding this comment.
Points 1 and 2 make sense - not necessarily as a performance optimization, but as a code-quality improvement.
Please revert point 3, as it changes the existing RawSql behavior.
If PR claims a performance improvement, please provide a reproducible benchmark and results demonstrating it. Otherwise, please use the refactor prefix. Performance claims should be supported by evidence provided by the PR author.
f7a23f0 to
07d2e7c
Compare
07d2e7c to
521a3e1
Compare
| $prefix = $this->{$clause} === [] ? $this->groupGetType('') : $this->groupGetType($type); | ||
|
|
There was a problem hiding this comment.
This needs the same empty-array guard as whereHaving(). groupGetType() mutates the group state, so calling it before an empty loop can break grouped queries like groupStart()->like([])->where(...), producing invalid SQL with AND immediately after (. Please add a regression test for that case.
Description
Inside
BaseBuilder'swhereHaving()and_like()methods,$this->groupGetType($type)was being called repeatedly insideforeachloops.This pull request optimizes these methods by:
$prefixoutside the loops before iteration starts.$prefixto$typeat the end of the loop iteration to correctly mimic subsequent query builder conditions._like()forRawSqlvs array inputs into a single loop using structured associative arrays (avoiding PHPTypeErrorsince array keys cannot beRawSqlobject instances).Checklist: