forgejo/models/db
Gusted 0418c19287
[GITEA] Add slow SQL query warning
- Databases are one of the most important parts of Forgejo, every
interaction with Forgejo uses the database in one way or another.
Therefore, it is important to maintain the database and recognize when
Forgejo is not doing well with the database. Forgejo already has the
option to log *every* SQL query along with its execution time, but
monitoring becomes impractical for larger instances and takes up
unnecessary storage in the logs.
- Add a QoL enhancement that allows instance administrators to specify a
threshold value beyond which query execution time is logged as a warning
in the xorm logger. The default value is a conservative five seconds to
avoid this becoming a source of spam in the logs.
- The use case for this patch is that with an instance the size of Codeberg, monitoring SQL logs is not very fruitful and most of them are uninteresting. Recently, in the context of persistent deadlock issues (https://codeberg.org/forgejo/forgejo/issues/220), I have noticed that certain queries hold locks on tables like comment and issue for several seconds. This patch helps to identify which queries these are and when they happen.
- Added unit test.

(cherry picked from commit 24bbe7886f)
(cherry picked from commit 6e29145b3c)
(cherry picked from commit 63731e3071)
(cherry picked from commit 3ce1a09736)
(cherry picked from commit a64426907d)
(cherry picked from commit 4b19215691)
(cherry picked from commit e635674435)
(cherry picked from commit 9cf501f1af)
(cherry picked from commit 0d6b934eba)
(cherry picked from commit 4b6c273879)
(cherry picked from commit b50517139c)
(cherry picked from commit 6546dd1fc9)
(cherry picked from commit 3eda6890e6)

[GITEA] Add slow SQL query warning (squash) document the setting

(cherry picked from commit ce38599c51)
(cherry picked from commit 794aa67c68)
(cherry picked from commit 8227673deb)
(cherry picked from commit 8854d1d4dd)
(cherry picked from commit 9121a0e21f)
(cherry picked from commit 41bae2e425)
2023-11-13 14:04:16 +01:00
..
install
paginator
common.go Fix NuGet search endpoints (#25613) 2023-08-14 02:50:55 +00:00
consistency.go
context.go Improve DeleteByID (#26904) 2023-09-05 08:11:35 +02:00
context_committer_test.go
context_test.go
convert.go
engine.go [GITEA] Add slow SQL query warning 2023-11-13 14:04:16 +01:00
engine_test.go [GITEA] Add slow SQL query warning 2023-11-13 14:04:16 +01:00
error.go Replace interface{} with any (#25686) 2023-07-04 18:36:08 +00:00
index.go
index_test.go
iterate.go
iterate_test.go
list.go
list_test.go
log.go Replace interface{} with any (#25686) 2023-07-04 18:36:08 +00:00
main_test.go
name.go
search.go Split lfs size from repository size (#22900) 2023-06-28 22:41:02 +00:00
sequence.go
sql_postgres_with_schema.go