Skip to content

Commit 6fb55e9

Browse files
Gustedearl-warren
authored andcommitted
[GITEA] Add slow SQL query warning (squash) Fix setting typo
- Fix typo in the slow query threshold setting, add a deprecation warning. - Resolves go-gitea#2203 (cherry picked from commit 02f6608e5fc21a0a00da5fc4c99152d43ee2ea4d) (cherry picked from commit 4e8f6b2ffdb25e0257933ee0a1bd21e3f4e86740)
1 parent 464ae81 commit 6fb55e9

3 files changed

Lines changed: 31 additions & 25 deletions

File tree

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
458458
- `MAX_IDLE_CONNS` **2**: Max idle database connections on connection pool, default is 2 - this will be capped to `MAX_OPEN_CONNS`.
459459
- `CONN_MAX_LIFETIME` **0 or 3s**: Sets the maximum amount of time a DB connection may be reused - default is 0, meaning there is no limit (except on MySQL where it is 3s - see #6804 & #7071).
460460
- `AUTO_MIGRATION` **true**: Whether execute database models migrations automatically.
461-
- `SLOW_QUERY_TRESHOLD` **5s**: Threshold value in seconds beyond which query execution time is logged as a warning in the xorm logger.
461+
- `SLOW_QUERY_THRESHOLD` **5s**: Threshold value in seconds beyond which query execution time is logged as a warning in the xorm logger.
462462

463463
[^1]: It may be necessary to specify a hostport even when listening on a unix socket, as the port is part of the socket name. see [#24552](https://github.com/go-gitea/gitea/issues/24552#issuecomment-1681649367) for additional details.
464464

models/db/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ func InitEngine(ctx context.Context) error {
147147
xormEngine.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
148148
xormEngine.SetDefaultContext(ctx)
149149

150-
if setting.Database.SlowQueryTreshold > 0 {
150+
if setting.Database.SlowQueryThreshold > 0 {
151151
xormEngine.AddHook(&SlowQueryHook{
152-
Treshold: setting.Database.SlowQueryTreshold,
152+
Treshold: setting.Database.SlowQueryThreshold,
153153
Logger: log.GetLogger("xorm"),
154154
})
155155
}

modules/setting/database.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ var (
2525

2626
// Database holds the database settings
2727
Database = struct {
28-
Type DatabaseType
29-
Host string
30-
Name string
31-
User string
32-
Passwd string
33-
Schema string
34-
SSLMode string
35-
Path string
36-
LogSQL bool
37-
MysqlCharset string
38-
CharsetCollation string
39-
Timeout int // seconds
40-
SQLiteJournalMode string
41-
DBConnectRetries int
42-
DBConnectBackoff time.Duration
43-
MaxIdleConns int
44-
MaxOpenConns int
45-
ConnMaxLifetime time.Duration
46-
IterateBufferSize int
47-
AutoMigration bool
48-
SlowQueryTreshold time.Duration
28+
Type DatabaseType
29+
Host string
30+
Name string
31+
User string
32+
Passwd string
33+
Schema string
34+
SSLMode string
35+
Path string
36+
LogSQL bool
37+
MysqlCharset string
38+
CharsetCollation string
39+
Timeout int // seconds
40+
SQLiteJournalMode string
41+
DBConnectRetries int
42+
DBConnectBackoff time.Duration
43+
MaxIdleConns int
44+
MaxOpenConns int
45+
ConnMaxLifetime time.Duration
46+
IterateBufferSize int
47+
AutoMigration bool
48+
SlowQueryThreshold time.Duration
4949
}{
5050
Timeout: 500,
5151
IterateBufferSize: 50,
@@ -88,7 +88,13 @@ func loadDBSetting(rootCfg ConfigProvider) {
8888
Database.DBConnectRetries = sec.Key("DB_RETRIES").MustInt(10)
8989
Database.DBConnectBackoff = sec.Key("DB_RETRY_BACKOFF").MustDuration(3 * time.Second)
9090
Database.AutoMigration = sec.Key("AUTO_MIGRATION").MustBool(true)
91-
Database.SlowQueryTreshold = sec.Key("SLOW_QUERY_TRESHOLD").MustDuration(5 * time.Second)
91+
92+
deprecatedSetting(rootCfg, "database", "SLOW_QUERY_TRESHOLD", "database", "SLOW_QUERY_THRESHOLD", "1.23")
93+
if sec.HasKey("SLOW_QUERY_TRESHOLD") && !sec.HasKey("SLOW_QUERY_THRESHOLD") {
94+
Database.SlowQueryThreshold = sec.Key("SLOW_QUERY_TRESHOLD").MustDuration(5 * time.Second)
95+
} else {
96+
Database.SlowQueryThreshold = sec.Key("SLOW_QUERY_THRESHOLD").MustDuration(5 * time.Second)
97+
}
9298
}
9399

94100
// DBConnStr returns database connection string

0 commit comments

Comments
 (0)