[PR #5359] [MERGED] perf(db): add an index on settings.key #5854

Closed
opened 2026-11-02 04:04:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5359
Author: @n0ctal
Created: 6/15/2026
Status: ✅ Merged
Merged: 6/20/2026
Merged by: @Mahyardana

Base: main ← Head: pr-0011-settings-key-index


📝 Commits (1)

  • 8f3ab97 perf(db): add an index on settings.key

📊 Changes

2 files changed (+31 additions, -1 deletions)

View changed files

📝 internal/database/model/model.go (+1 -1)
➕ internal/database/settings_index_test.go (+30 -0)

📄 Description

Summary

Adds a database index on settings.key so the hottest config lookup no longer full-scans the table.

Why

getSetting (WHERE key = ?) runs on nearly every subscription request and job tick. settings.key had no index, so each lookup full-scans the settings table — including past the large xrayTemplateConfig blob.

Scope

  • adds index idx_settings_key on settings.key
  • AutoMigrate creates it on existing databases on upgrade
  • no behavior change

Validation

  • HasIndex unit test after AutoMigrate
  • database package tests pass

Risk

Low. Index-only addition, no schema or behavior change, idempotent migration.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5359 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/15/2026 **Status:** ✅ Merged **Merged:** 6/20/2026 **Merged by:** [@Mahyardana](https://github.com/Mahyardana) **Base:** `main` ← **Head:** `pr-0011-settings-key-index` --- ### 📝 Commits (1) - [`8f3ab97`](https://github.com/MHSanaei/3x-ui/commit/8f3ab974fe5627322487a5e39867f1df8210c175) perf(db): add an index on settings.key ### 📊 Changes **2 files changed** (+31 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `internal/database/model/model.go` (+1 -1) ➕ `internal/database/settings_index_test.go` (+30 -0) </details> ### 📄 Description ## Summary Adds a database index on `settings.key` so the hottest config lookup no longer full-scans the table. ## Why `getSetting` (`WHERE key = ?`) runs on nearly every subscription request and job tick. `settings.key` had no index, so each lookup full-scans the `settings` table — including past the large `xrayTemplateConfig` blob. ## Scope - adds index `idx_settings_key` on `settings.key` - `AutoMigrate` creates it on existing databases on upgrade - no behavior change ## Validation - `HasIndex` unit test after `AutoMigrate` - `database` package tests pass ## Risk Low. Index-only addition, no schema or behavior change, idempotent migration. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:33 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5854
No description provided.