Skip to content

Commit 94f670a

Browse files
authored
Improve explain on db_logging (#1898)
1 parent 7103c0b commit 94f670a

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,16 @@ release_major: gen_major
109109
TESTS_PHP := $(shell find tests/Feature -name "*Test.php" -printf "%f\n")
110110
TEST_DONE := $(addprefix build/,$(TESTS_PHP:.php=.done))
111111

112-
build/%.done: tests/Feature/%.php
113-
XDEBUG_MODE=coverage vendor/bin/phpunit --filter $* && touch build/$*.done
112+
build:
113+
mkdir build
114+
115+
build/Base%.done:
116+
touch build/Base$*.done
117+
118+
build/%UnitTest.done:
119+
touch build/$*UnitTest.done
120+
121+
build/%.done: tests/Feature/%.php build
122+
vendor/bin/phpunit --no-coverage --filter $* && touch build/$*.done
114123

115124
all_tests: $(TEST_DONE)

app/Providers/AppServiceProvider.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@
3838

3939
class AppServiceProvider extends ServiceProvider
4040
{
41+
/**
42+
* Defines which queries to ignore when doing explain.
43+
*
44+
* @var array<int,string>
45+
*/
46+
private array $ignore_log_SQL =
47+
[
48+
'information_schema', // Not interesting
49+
50+
// We do not want infinite loops
51+
'EXPLAIN',
52+
53+
// Way too noisy
54+
'configs',
55+
];
56+
4157
public array $singletons =
4258
[
4359
SymLinkFunctions::class => SymLinkFunctions::class,
@@ -151,8 +167,7 @@ private function logSQL(QueryExecuted $query): void
151167
{
152168
// Quick exit
153169
if (
154-
Str::contains(request()->getRequestUri(), 'logs', true) ||
155-
Str::contains($query->sql, ['information_schema', 'EXPLAIN', 'configs'])
170+
Str::contains(request()->getRequestUri(), 'logs', true)
156171
) {
157172
return;
158173
}
@@ -161,7 +176,11 @@ private function logSQL(QueryExecuted $query): void
161176
$msg = '(' . $query->time . 'ms) ' . $query->sql . ' [' . implode(', ', $query->bindings) . ']';
162177

163178
// For pgsql and sqlite we log the query and exit early
164-
if (config('database.default', 'mysql') !== 'mysql' || config('database.explain', false) === false) {
179+
if (config('database.default', 'mysql') !== 'mysql' ||
180+
config('database.explain', false) === false ||
181+
!Str::contains($query->sql, 'select') ||
182+
Str::contains($query->sql, $this->ignore_log_SQL)
183+
) {
165184
Log::debug($msg);
166185

167186
return;

database/migrations/2018_08_15_102039_move_albums.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public function up(): void
3838
]);
3939
}
4040
} else {
41-
Log::notice(__FUNCTION__ . ':' . __LINE__ . ' ' . env('DB_OLD_LYCHEE_PREFIX', '') . 'lychee_albums does not exist!');
41+
Log::notice(__METHOD__ . ':' . __LINE__ . ' ' . env('DB_OLD_LYCHEE_PREFIX', '') . 'lychee_albums does not exist!');
4242
}
4343
} else {
44-
Log::notice(__FUNCTION__ . ':' . __LINE__ . ' albums is not empty.');
44+
Log::notice(__METHOD__ . ':' . __LINE__ . ' albums is not empty.');
4545
}
4646
}
4747

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<php>
2929
<env name="APP_ENV" value="testing"/>
3030
<env name="DB_LOG_SQL" value="true"/>
31+
<env name="DB_LOG_SQL_EXPLAIN" value="true"/>
3132
<env name="BCRYPT_ROUNDS" value="4"/>
3233
<env name="CACHE_DRIVER" value="array"/>
3334
<env name="SESSION_DRIVER" value="array"/>

tests/Feature/WebAuthTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function setUp(): void
3030
{
3131
parent::setUp();
3232
$this->setUpRequiresEmptyWebAuthnCredentials();
33+
config(['app.url' => 'https://localhost']);
3334
}
3435

3536
public function tearDown(): void

0 commit comments

Comments
 (0)