diff --git a/app/Livewire/Developer/Settings.php b/app/Livewire/Developer/Settings.php
index fb73eb6c4..a415e42db 100644
--- a/app/Livewire/Developer/Settings.php
+++ b/app/Livewire/Developer/Settings.php
@@ -20,12 +20,6 @@ class Settings extends Component
public SettingsForm $settingsForm;
- public bool $logAllQueries = false;
-
- public bool $logAllQueriesSlow = false;
-
- public bool $logAllQueriesNPlusOne = false;
-
/**
* Mount the component and load initial data.
*/
@@ -34,13 +28,10 @@ public function mount(): void
// Fetch settings and map them to the properties
$this->settings = Setting::pluck('value', 'key');
- $this->settingsForm->logAllQueries = (bool) $this->settings->get('log_all_queries');
- $this->settingsForm->logAllQueriesSlow = (bool) $this->settings->get('log_all_queries_slow');
- $this->settingsForm->logAllQueriesNPlusOne = (bool) $this->settings->get('log_all_queries_nplusone');
-
- $this->logAllQueries = (bool) $this->settings->get('log_all_queries');
- $this->logAllQueriesSlow = (bool) $this->settings->get('log_all_queries_slow');
- $this->logAllQueriesNPlusOne = (bool) $this->settings->get('log_all_queries_nplusone');
+ $this->settingsForm->logAllQueries = (bool) $this->settings->get('log_all_queries');
+ $this->settingsForm->logAllQueriesSlowThreshold = $this->settings->get('log_all_queries_slow_threshold');
+ $this->settingsForm->logAllQueriesSlow = (bool) $this->settings->get('log_all_queries_slow');
+ $this->settingsForm->logAllQueriesNPlusOne = (bool) $this->settings->get('log_all_queries_nplusone');
}
/**
@@ -49,13 +40,14 @@ public function mount(): void
public function saveSettings(): void
{
$settings = [
- 'log_all_queries' => $this->settingsForm->logAllQueries,
- 'log_all_queries_slow' => $this->settingsForm->logAllQueriesSlow,
- 'log_all_queries_nplusone' => $this->settingsForm->logAllQueriesNPlusOne,
+ 'log_all_queries' => $this->settingsForm->logAllQueries,
+ 'log_all_queries_slow' => $this->settingsForm->logAllQueriesSlow,
+ 'log_all_queries_slow_threshold' => $this->settingsForm->logAllQueriesSlowThreshold,
+ 'log_all_queries_nplusone' => $this->settingsForm->logAllQueriesNPlusOne,
];
foreach ($settings as $key => $value) {
- Setting::updateOrCreate(['key' => $key], ['value' => $value ? 1 : 0]);
+ Setting::updateOrCreate(['key' => $key], ['value' => $value]);
}
// Clear the cache
@@ -72,9 +64,10 @@ public function resetSettings(): void
public function isDirty(): bool
{
return
- $this->settingsForm->logAllQueries != $this->logAllQueries or
- $this->settingsForm->logAllQueriesSlow != $this->logAllQueriesSlow or
- $this->settingsForm->logAllQueriesNPlusOne != $this->logAllQueriesNPlusOned;
+ $this->settingsForm->logAllQueries != (bool) $this->settings->get('log_all_queries') or
+ $this->settingsForm->logAllQueriesSlow != $this->settings->get('log_all_queries_slow_threshold') or
+ $this->settingsForm->logAllQueriesSlowThreshold != $this->logAllQueriesSlowThreshold or (bool) $this->settings->get('log_all_queries_slow') or
+ $this->settingsForm->logAllQueriesNPlusOne != (bool) $this->settings->get('log_all_queries_nplusone');
}
/**
diff --git a/app/Livewire/Forms/Developer/SettingsForm.php b/app/Livewire/Forms/Developer/SettingsForm.php
index 688f4cea7..40de5401e 100644
--- a/app/Livewire/Forms/Developer/SettingsForm.php
+++ b/app/Livewire/Forms/Developer/SettingsForm.php
@@ -13,12 +13,19 @@ class SettingsForm extends Form
public bool $logAllQueriesSlow = false;
+ public string $logAllQueriesSlowThreshold = '500';
+
public bool $logAllQueriesNPlusOne = false;
// -----------------------------------------------------------------------
public function rules(): array
{
- return $rules = [];
+ return $rules = [
+ 'log_all_queries' => ['boolean'],
+ 'log_all_queries_slow' => ['boolean'],
+ 'log_all_queries_slow_threshold' => ['integer'],
+ 'log_all_queries_nplusone' => ['boolean'],
+ ];
}
public function messages(): array
@@ -28,6 +35,11 @@ public function messages(): array
public function validationAttributes(): array
{
- return [];
+ return [
+ 'log_all_queries' => __('settings.log_all_queries'),
+ 'log_all_queries_slow' => __('settings.log_all_queries_slow'),
+ 'log_all_queries_slow_threshold' => __('settings.log_all_queries_slow_threshold'),
+ 'log_all_queries_nplusone' => __('settings.log_all_queries_nplusone'),
+ ];
}
}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index df28f54aa..97a4c10bd 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -176,14 +176,14 @@ private function logAllQueries(): void
}
/**
- * Log all slow queries (threshold in ms) for debugging purposes.
+ * Log all slow queries for debugging purposes.
*/
- private function LogAllQueriesSlow(int $threshold = 500): void
+ private function LogAllQueriesSlow(): void
{
if (settings('log_all_queries_slow')) {
- DB::listen(function ($query) use ($threshold) {
- if ($query->time >= $threshold) {
- Log::warning('An individual database query exceeded ' . $threshold . ' ms.', [
+ DB::listen(function ($query) {
+ if ($query->time >= settings('log_all_queries_slow_threshold')) {
+ Log::warning('An individual database query exceeded ' . settings('log_all_queries_slow_threshold') . ' ms.', [
'sql' => $query->sql,
'raw' => $query->toRawSQL(),
]);
diff --git a/database/seeders/SettingSeeder.php b/database/seeders/SettingSeeder.php
index 7b50e7d82..e57143597 100644
--- a/database/seeders/SettingSeeder.php
+++ b/database/seeders/SettingSeeder.php
@@ -15,6 +15,7 @@ public function run(): void
$settingsData = [
['key' => 'log_all_queries', 'value' => false],
['key' => 'log_all_queries_slow', 'value' => true],
+ ['key' => 'log_all_queries_slow_threshold', 'value' => 500],
['key' => 'log_all_queries_nplusone', 'value' => true],
];
diff --git a/lang/de/settings.php b/lang/de/settings.php
index ccbe27ca9..7d55bcbba 100644
--- a/lang/de/settings.php
+++ b/lang/de/settings.php
@@ -1,7 +1,8 @@
'Protokolliere ALLE Datenbankabfragen',
- 'log_all_queries_slow' => 'Protokolliere alle LANGSAMEN Datenbankabfragen',
- 'log_all_queries_nplusone' => 'Protokolliere alle (N+1)) Datenbankabfragen',
+ 'log_all_queries' => 'Protokolliere ALLE Datenbankabfragen',
+ 'log_all_queries_slow' => 'Protokolliere alle LANGSAMEN Datenbankabfragen',
+ 'log_all_queries_slow_threshold' => 'Schwelle (in ms)',
+ 'log_all_queries_nplusone' => 'Protokolliere alle (N+1)) Datenbankabfragen',
];
diff --git a/lang/en/settings.php b/lang/en/settings.php
index e4415a28a..a002e646a 100644
--- a/lang/en/settings.php
+++ b/lang/en/settings.php
@@ -1,7 +1,8 @@
'Log ALL database queries',
- 'log_all_queries_slow' => 'Log all SLOW database queries',
- 'log_all_queries_nplusone' => 'Log all (N+1) database queries',
+ 'log_all_queries' => 'Log ALL database queries',
+ 'log_all_queries_slow' => 'Log all SLOW database queries',
+ 'log_all_queries_slow_threshold' => 'Threshold (in ms)',
+ 'log_all_queries_nplusone' => 'Log all (N+1) database queries',
];
diff --git a/lang/es/settings.php b/lang/es/settings.php
index 7ebb1bcfb..ed913e15a 100644
--- a/lang/es/settings.php
+++ b/lang/es/settings.php
@@ -1,7 +1,8 @@
'Registrar TODAS las consultas de la base de datos',
- 'log_all_queries_slow' => 'Registre todas las consultas de bases de datos LENTAS',
- 'log_all_queries_nplusone' => 'Registrar todas las consultas de la base de datos (N+1)',
+ 'log_all_queries' => 'Registrar TODAS las consultas de la base de datos',
+ 'log_all_queries_slow' => 'Registre todas las consultas de bases de datos LENTAS',
+ 'log_all_queries_slow_threshold' => 'Límite (en ms)',
+ 'log_all_queries_nplusone' => 'Registrar todas las consultas de la base de datos (N+1)',
];
diff --git a/lang/fr/settings.php b/lang/fr/settings.php
index 9571ca67b..ea5088b72 100644
--- a/lang/fr/settings.php
+++ b/lang/fr/settings.php
@@ -1,7 +1,8 @@
'Enregistrez TOUTES les requêtes de base de données',
- 'log_all_queries_slow' => 'Enregistrez toutes les requêtes de base de données LENTES',
- 'log_all_queries_nplusone' => 'Enregistrer toutes les requêtes de base de données (N+1)',
+ 'log_all_queries' => 'Enregistrez TOUTES les requêtes de base de données',
+ 'log_all_queries_slow' => 'Enregistrez toutes les requêtes de base de données LENTES',
+ 'log_all_queries_slow_threshold' => 'Seuil (en ms)',
+ 'log_all_queries_nplusone' => 'Enregistrer toutes les requêtes de base de données (N+1)',
];
diff --git a/lang/nl/settings.php b/lang/nl/settings.php
index c609f6ee0..c1cd9f444 100644
--- a/lang/nl/settings.php
+++ b/lang/nl/settings.php
@@ -1,7 +1,8 @@
'Registreer ALLE databasequery\'s',
- 'log_all_queries_slow' => 'Registreer alle TRAGE databasequery\'s',
- 'log_all_queries_nplusone' => 'Registreer alle (N+1) databasequery\'s',
+ 'log_all_queries' => 'Registreer ALLE databasequery\'s',
+ 'log_all_queries_slow' => 'Registreer alle TRAGE databasequery\'s',
+ 'log_all_queries_slow_threshold' => 'Drempelwaarde (in ms)',
+ 'log_all_queries_nplusone' => 'Registreer alle (N+1) databasequery\'s',
];
diff --git a/lang/pt/settings.php b/lang/pt/settings.php
index 711706bac..b8eff9826 100644
--- a/lang/pt/settings.php
+++ b/lang/pt/settings.php
@@ -1,7 +1,8 @@
'Registrar TODAS as consultas do banco de dados',
- 'log_all_queries_slow' => 'Registrar todas as consultas LENTAS do banco de dados',
- 'log_all_queries_nplusone' => 'Registrar todas as consultas do banco de dados (N+1)',
+ 'log_all_queries' => 'Registrar TODAS as consultas do banco de dados',
+ 'log_all_queries_slow' => 'Registrar todas as consultas LENTAS do banco de dados',
+ 'log_all_queries_slow_threshold' => 'Limite (em ms)',
+ 'log_all_queries_nplusone' => 'Registrar todas as consultas do banco de dados (N+1)',
];
diff --git a/lang/vi/settings.php b/lang/vi/settings.php
index f6e0520c7..59de1100f 100644
--- a/lang/vi/settings.php
+++ b/lang/vi/settings.php
@@ -1,7 +1,8 @@
'Đăng nhập TẤT CẢ các truy vấn cơ sở dữ liệu',
- 'log_all_queries_slow' => 'Ghi lại tất cả các truy vấn cơ sở dữ liệu CHẬM',
- 'log_all_queries_nplusone' => 'Ghi nhật ký tất cả (N+1) truy vấn cơ sở dữ liệu',
+ 'log_all_queries' => 'Đăng nhập TẤT CẢ các truy vấn cơ sở dữ liệu',
+ 'log_all_queries_slow' => 'Ghi lại tất cả các truy vấn cơ sở dữ liệu CHẬM',
+ 'log_all_queries_slow_threshold' => 'Ngưỡng (tính bằng mili giây)',
+ 'log_all_queries_nplusone' => 'Ghi nhật ký tất cả (N+1) truy vấn cơ sở dữ liệu',
];
diff --git a/lang/zh_cn/settings.php b/lang/zh_cn/settings.php
index 1235f34d2..2a1a79336 100644
--- a/lang/zh_cn/settings.php
+++ b/lang/zh_cn/settings.php
@@ -1,7 +1,8 @@
'记录所有数据库查询',
- 'log_all_queries_slow' => '记录所有 SLOW 数据库查询',
- 'log_all_queries_nplusone' => 'L记录所有 (N+1) 数据库查询',
+ 'log_all_queries' => '记录所有数据库查询',
+ 'log_all_queries_slow' => '记录所有 SLOW 数据库查询',
+ 'log_all_queries_slow_threshold' => '阈值(以毫秒为单位)',
+ 'log_all_queries_nplusone' => 'L记录所有 (N+1) 数据库查询',
];
diff --git a/resources/views/livewire/developer/settings.blade.php b/resources/views/livewire/developer/settings.blade.php
index 0a560bef1..a87891e04 100644
--- a/resources/views/livewire/developer/settings.blade.php
+++ b/resources/views/livewire/developer/settings.blade.php
@@ -27,10 +27,18 @@