forgejo-federation/models/db
Gusted 664192767c
[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 24bbe7886fb4cb9a38c8dab8c44f4c9cbfa25481)
(cherry picked from commit 6e29145b3c1455498531593d38e6a914941a12cb)
(cherry picked from commit 63731e30712872bd2395eb3cf36d9996e5793645)
(cherry picked from commit 3ce1a097369c132654de70df707b867e47bd1c40)
(cherry picked from commit a64426907de788cc0937a7a2b16af4d2f26f7fe6)
(cherry picked from commit 4b1921569156445c58d9889602733da5934c7b95)
(cherry picked from commit e6356744359fa947c049827d60c2ea0e277e03dc)
(cherry picked from commit 9cf501f1af4cd870221cef6af489618785b71186)
(cherry picked from commit 0d6b934eba1c0e9b27b364791113aae816b6b366)
(cherry picked from commit 4b6c2738795002887844a106f2fed2ef1673eed1)
(cherry picked from commit 89b1315338b0c7a726a36a84e9844013a13560b8)
(cherry picked from commit edd8e66ce991c395bb0af7720631c3cd26caaa51)

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

(cherry picked from commit ce38599c5141c7fc6bc054819f5ff1c1b45bda1f)
(cherry picked from commit 794aa67c68c8e24ac7301eb7ef767c6e2499a78d)
(cherry picked from commit a4c2c6b004c21488e90f637ca7920f49108ed75d)
(cherry picked from commit 97912752bc802db79bb26a6591aec885aea30ee4)
(cherry picked from commit 00b5327c9750215a290238516e7b6fb1e6601e14)
(cherry picked from commit 1069c860e78c11225b4d74ff3044df7786562821)
(cherry picked from commit 84241f42c83852918b57c8bd25364697037fe42f)
(cherry picked from commit e4bda0e8457d00c01b83f153ed5a4a8ea4cf85c8)
(cherry picked from commit 7357fb91bff87045b133c3a7ac9fc70eea781bc4)
(cherry picked from commit a8dd7f6da278ae112200b5efa5bf27e3961f5996)
(cherry picked from commit e636e9f4beca7273dd8622baedb2f0c01db30449)
(cherry picked from commit bf04ae86037f5cb5a81d02750aead2742b040367)
(cherry picked from commit 93b19e3568169bd1cf9b8b78c1751c3d2d65a1b6)
(cherry picked from commit 83f91363ad071675c73a1f636271cc043bf69707)
(cherry picked from commit e34a05bc7319072b70d387975342d617b8136655)
(cherry picked from commit 68569aeee9805aaa8e98c6e7fe8058095e290061)
2024-02-05 16:05:50 +01:00
..
install Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
paginator Move more functions to db.Find (#28419) 2024-01-15 02:19:25 +00:00
collation.go Recommend/convert to use case-sensitive collation for MySQL/MSSQL (#28662) 2024-01-10 11:03:23 +00:00
common.go Fix NuGet search endpoints (#25613) 2023-08-14 02:50:55 +00:00
consistency.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
context.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
context_committer_test.go Fix halfCommitter and WithTx (#22366) 2023-01-09 12:19:19 -05:00
context_test.go Always reuse transaction (#22362) 2023-01-08 09:34:58 +08:00
convert.go Recommend/convert to use case-sensitive collation for MySQL/MSSQL (#28662) 2024-01-10 11:03:23 +00:00
engine.go [GITEA] Add slow SQL query warning 2024-02-05 16:05:50 +01:00
engine_test.go [GITEA] Add slow SQL query warning 2024-02-05 16:05:50 +01:00
error.go Refactor deletion (#28610) 2023-12-25 21:25:29 +01:00
index.go Fix index generation parallelly failure (#25235) 2023-06-15 02:14:43 +02:00
index_test.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
iterate.go refactor: make db iterate context aware (#27710) 2023-10-21 10:05:29 +08:00
iterate_test.go Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (#28220) 2023-12-07 15:27:36 +08:00
list.go Fix joins in db.Find(AndCount) (#28978) 2024-01-30 02:37:24 +00:00
list_test.go Use db.Find instead of writing methods for every object (#28084) 2023-11-24 03:49:41 +00:00
log.go Replace interface{} with any (#25686) 2023-07-04 18:36:08 +00:00
main_test.go make writing main test easier (#27270) 2023-09-28 01:38:53 +00:00
name.go Implement FSFE REUSE for golang files (#21840) 2022-11-27 18:20:29 +00:00
search.go Split lfs size from repository size (#22900) 2023-06-28 22:41:02 +00:00
sequence.go Refactor setting.Database.UseXXX to methods (#23354) 2023-03-07 18:51:06 +08:00
sql_postgres_with_schema.go Fix .golangci.yml (#22868) 2023-02-11 21:44:53 +00:00