perf(db): add an index on settings.key (#5359)

getSetting (WHERE key=?) runs on nearly every subscription request and job
tick and had no index, so each lookup full-scans the settings table past the
large xrayTemplateConfig blob. Add an index on settings.key; AutoMigrate
creates it on existing DBs too. Includes a HasIndex test.
This commit is contained in:
n0ctal authored and GitHub committed 2026-06-20 15:08:54 +03:30
1 parent 26cc4838ed
commit 3cf3fddf12
2 files changed
+31 -1

No files matched your search

+1 -1
View File
@@ -486,7 +486,7 @@ func HealMtprotoSecret(settings string) (string, bool) {
// Setting stores key-value configuration settings for the 3x-ui panel.
type Setting struct {
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
Key string `json:"key" form:"key"`
Key string `json:"key" form:"key" gorm:"index:idx_settings_key"`
Value string `json:"value" form:"value"`
}