mirror of
https://github.com/gravitl/netmaker.git
synced 2026-04-23 00:17:10 +08:00
NM-256: fix DB performance degradation with large user base and Entra IDP
- Replace full table scan in FetchRecord with indexed single-key lookup
(SELECT WHERE key = ?) for PostgreSQL, SQLite, and RQLite backends
- Add in-memory user cache (gated behind CACHING_ENABLED) to eliminate
DB round-trips on the auth hot path (GetUser called per API request)
- Configure PostgreSQL connection pool limits (max open/idle conns,
conn lifetime) to prevent connection churn under load
- Add periodic cleanup of expired SSO state entries to prevent
unbounded table growth
- Route GitHub OAuth user rename through standard logic functions
to keep user cache consistent
This commit is contained in:
@@ -20,6 +20,7 @@ var SQLITE_FUNCTIONS = map[string]interface{}{
|
||||
DELETE: sqliteDeleteRecord,
|
||||
DELETE_ALL: sqliteDeleteAllRecords,
|
||||
FETCH_ALL: sqliteFetchRecords,
|
||||
FETCH_ONE: sqliteFetchRecord,
|
||||
CLOSE_DB: sqliteCloseDB,
|
||||
isConnected: sqliteConnected,
|
||||
}
|
||||
@@ -103,6 +104,18 @@ func sqliteDeleteAllRecords(tableName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func sqliteFetchRecord(tableName string, key string) (string, error) {
|
||||
var value string
|
||||
err := SqliteDB.QueryRow("SELECT value FROM "+tableName+" WHERE key = ?", key).Scan(&value)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return "", errors.New(NO_RECORD)
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func sqliteFetchRecords(tableName string) (map[string]string, error) {
|
||||
row, err := SqliteDB.Query("SELECT * FROM " + tableName + " ORDER BY key")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user