Skip to content

Performance Improvement: Database Query Log Memory Optimization #56506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 12.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix code style
  • Loading branch information
AmirHossein Fallah committed Jul 31, 2025
commit 7194e7d1409b9a732cb3e7b10edd8422d3037ac0
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ public function logQuery($query, $bindings, $time = null)

if ($this->loggingQueries) {
$this->queryLog[] = compact('query', 'bindings', 'time');

if (count($this->queryLog) > $this->maxQueryLogSize) {
$this->queryLog = array_slice($this->queryLog, -$this->maxQueryLogSize, $this->maxQueryLogSize, false);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Database/DatabaseConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,11 @@ public function testQueryLogSizeLimit()
$this->assertEquals(3, $connection->getMaxQueryLogSize());

for ($i = 0; $i < 5; $i++) {
$connection->logQuery("SELECT * FROM test WHERE id = ?", [$i], 10.0);
$connection->logQuery('SELECT * FROM test WHERE id = ?', [$i], 10.0);
}

$queryLog = $connection->getQueryLog();

$this->assertCount(3, $queryLog);
$this->assertEquals([2], $queryLog[0]['bindings']);
$this->assertEquals([3], $queryLog[1]['bindings']);
Expand All @@ -573,10 +573,10 @@ public function testQueryLogSizeLimit()
public function testQueryLogSizeLimitMinimumValue()
{
$connection = $this->getMockConnection();

$connection->setMaxQueryLogSize(0);
$this->assertEquals(1, $connection->getMaxQueryLogSize());

$connection->setMaxQueryLogSize(-5);
$this->assertEquals(1, $connection->getMaxQueryLogSize());
}
Expand Down
Loading