Skip to content

perf(database): optimize groupGetType by caching it inside BaseBuilder loops#10340

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:perf/optimize-basebuilder
Open

perf(database): optimize groupGetType by caching it inside BaseBuilder loops#10340
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:perf/optimize-basebuilder

Conversation

@gr8man

@gr8man gr8man commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description
Inside BaseBuilder's whereHaving() and _like() methods, $this->groupGetType($type) was being called repeatedly inside foreach loops.

This pull request optimizes these methods by:

  1. Caching the $prefix outside the loops before iteration starts.
  2. Dynamically updating the $prefix to $type at the end of the loop iteration to correctly mimic subsequent query builder conditions.
  3. Unifying the separate logical paths in _like() for RawSql vs array inputs into a single loop using structured associative arrays (avoiding PHP TypeError since array keys cannot be RawSql object instances).

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide
  • We don't add entries for refactoring, as there are no real changes for end users. (No changelog entry needed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant