s/Get(Master|Replica)X/Get\1/g (#29520)
Drop the legacy `X` suffix from `GetMasterX` and `GetReplicaX`. The presence of the suffix suggests there's a `non-X` version: but in fact we migrated these away a long time ago, so remove the cognitive overhead. As an aside, this additionally helps avoid trip up LLMs that interpret this as "something to fix".
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8b86e1276e
Коммит
5369f8b36b
@@ -374,7 +374,7 @@ func (ss *SqlStore) computeDefaultTextSearchConfig() (string, error) {
|
||||
}
|
||||
|
||||
var defaultTextSearchConfig string
|
||||
err := ss.GetMasterX().Get(&defaultTextSearchConfig, `SHOW default_text_search_config`)
|
||||
err := ss.GetMaster().Get(&defaultTextSearchConfig, `SHOW default_text_search_config`)
|
||||
return defaultTextSearchConfig, err
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ func (ss *SqlStore) GetDbVersion(numerical bool) (string, error) {
|
||||
}
|
||||
|
||||
var version string
|
||||
err := ss.GetReplicaX().Get(&version, sqlVersion)
|
||||
err := ss.GetReplica().Get(&version, sqlVersion)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -408,7 +408,7 @@ func (ss *SqlStore) GetDbVersion(numerical bool) (string, error) {
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetMasterX() *sqlxDBWrapper {
|
||||
func (ss *SqlStore) GetMaster() *sqlxDBWrapper {
|
||||
return ss.masterX
|
||||
}
|
||||
|
||||
@@ -422,16 +422,16 @@ func (ss *SqlStore) SetMasterX(db *sql.DB) {
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetInternalMasterDB() *sql.DB {
|
||||
return ss.GetMasterX().DB.DB
|
||||
return ss.GetMaster().DB.DB
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetSearchReplicaX() *sqlxDBWrapper {
|
||||
if !ss.hasLicense() {
|
||||
return ss.GetMasterX()
|
||||
return ss.GetMaster()
|
||||
}
|
||||
|
||||
if len(ss.settings.DataSourceSearchReplicas) == 0 {
|
||||
return ss.GetReplicaX()
|
||||
return ss.GetReplica()
|
||||
}
|
||||
|
||||
for i := 0; i < len(ss.searchReplicaXs); i++ {
|
||||
@@ -442,12 +442,12 @@ func (ss *SqlStore) GetSearchReplicaX() *sqlxDBWrapper {
|
||||
}
|
||||
|
||||
// If all search replicas are down, then go with replica.
|
||||
return ss.GetReplicaX()
|
||||
return ss.GetReplica()
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetReplicaX() *sqlxDBWrapper {
|
||||
func (ss *SqlStore) GetReplica() *sqlxDBWrapper {
|
||||
if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster || !ss.hasLicense() {
|
||||
return ss.GetMasterX()
|
||||
return ss.GetMaster()
|
||||
}
|
||||
|
||||
for i := 0; i < len(ss.ReplicaXs); i++ {
|
||||
@@ -458,7 +458,7 @@ func (ss *SqlStore) GetReplicaX() *sqlxDBWrapper {
|
||||
}
|
||||
|
||||
// If all replicas are down, then go with master.
|
||||
return ss.GetMasterX()
|
||||
return ss.GetMaster()
|
||||
}
|
||||
|
||||
func (ss *SqlStore) monitorReplicas() {
|
||||
@@ -512,7 +512,7 @@ func (ss *SqlStore) setDB(replica *atomic.Pointer[sqlxDBWrapper], handle *dbsql.
|
||||
|
||||
func (ss *SqlStore) GetInternalReplicaDB() *sql.DB {
|
||||
if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster || !ss.hasLicense() {
|
||||
return ss.GetMasterX().DB.DB
|
||||
return ss.GetMaster().DB.DB
|
||||
}
|
||||
|
||||
rrNum := atomic.AddInt64(&ss.rrCounter, 1) % int64(len(ss.ReplicaXs))
|
||||
@@ -520,7 +520,7 @@ func (ss *SqlStore) GetInternalReplicaDB() *sql.DB {
|
||||
}
|
||||
|
||||
func (ss *SqlStore) TotalMasterDbConnections() int {
|
||||
return ss.GetMasterX().Stats().OpenConnections
|
||||
return ss.GetMaster().Stats().OpenConnections
|
||||
}
|
||||
|
||||
// ReplicaLagAbs queries all the replica databases to get the absolute replica lag value
|
||||
@@ -609,7 +609,7 @@ func (ss *SqlStore) MarkSystemRanUnitTests() {
|
||||
func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT count(relname) FROM pg_class WHERE relname=$1`,
|
||||
strings.ToLower(tableName),
|
||||
)
|
||||
@@ -621,7 +621,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
return count > 0
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT
|
||||
COUNT(0) AS table_exists
|
||||
FROM
|
||||
@@ -646,7 +646,7 @@ func (ss *SqlStore) DoesTableExist(tableName string) bool {
|
||||
func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT COUNT(0)
|
||||
FROM pg_attribute
|
||||
WHERE attrelid = $1::regclass
|
||||
@@ -667,7 +667,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
return count > 0
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count,
|
||||
err := ss.GetMaster().Get(&count,
|
||||
`SELECT
|
||||
COUNT(0) AS column_exists
|
||||
FROM
|
||||
@@ -693,7 +693,7 @@ func (ss *SqlStore) DoesColumnExist(tableName string, columnName string) bool {
|
||||
func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count, `
|
||||
err := ss.GetMaster().Get(&count, `
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
@@ -709,7 +709,7 @@ func (ss *SqlStore) DoesTriggerExist(triggerName string) bool {
|
||||
return count > 0
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
var count int64
|
||||
err := ss.GetMasterX().Get(&count, `
|
||||
err := ss.GetMaster().Get(&count, `
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
@@ -735,14 +735,14 @@ func (ss *SqlStore) CreateColumnIfNotExists(tableName string, columnName string,
|
||||
}
|
||||
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
_, err := ss.GetMasterX().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'")
|
||||
_, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'")
|
||||
if err != nil {
|
||||
mlog.Fatal("Failed to create column", mlog.Err(err))
|
||||
}
|
||||
|
||||
return true
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
_, err := ss.GetMasterX().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'")
|
||||
_, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'")
|
||||
if err != nil {
|
||||
mlog.Fatal("Failed to create column", mlog.Err(err))
|
||||
}
|
||||
@@ -758,7 +758,7 @@ func (ss *SqlStore) RemoveTableIfExists(tableName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
_, err := ss.GetMasterX().ExecNoTimeout("DROP TABLE " + tableName)
|
||||
_, err := ss.GetMaster().ExecNoTimeout("DROP TABLE " + tableName)
|
||||
if err != nil {
|
||||
mlog.Fatal("Failed to drop table", mlog.Err(err))
|
||||
}
|
||||
@@ -1195,7 +1195,7 @@ func (ss *SqlStore) ensureDatabaseCollation() error {
|
||||
Variable_name string
|
||||
Value string
|
||||
}
|
||||
if err := ss.GetMasterX().Get(&connCollation, "SHOW VARIABLES LIKE 'collation_connection'"); err != nil {
|
||||
if err := ss.GetMaster().Get(&connCollation, "SHOW VARIABLES LIKE 'collation_connection'"); err != nil {
|
||||
return errors.Wrap(err, "unable to select variables")
|
||||
}
|
||||
|
||||
@@ -1205,14 +1205,14 @@ func (ss *SqlStore) ensureDatabaseCollation() error {
|
||||
// we check if table exists because this code runs before the migrations applied
|
||||
// which means if there is a fresh db, we may fail on selecting the table_collation
|
||||
var exists int
|
||||
if err := ss.GetMasterX().Get(&exists, "SELECT count(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
if err := ss.GetMaster().Get(&exists, "SELECT count(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("unable to check if table exists for collation check: %q", tableName))
|
||||
} else if exists == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var tableCollation string
|
||||
if err := ss.GetMasterX().Get(&tableCollation, "SELECT table_collation FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
if err := ss.GetMaster().Get(&tableCollation, "SELECT table_collation FROM information_schema.tables WHERE table_schema = DATABASE() AND LOWER(table_name) = ?", tableName); err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("unable to get table collation: %q", tableName))
|
||||
}
|
||||
|
||||
@@ -1283,7 +1283,7 @@ func (ss *SqlStore) GetLocalSchemaVersion() (int, error) {
|
||||
|
||||
func (ss *SqlStore) GetDBSchemaVersion() (int, error) {
|
||||
var version int
|
||||
if err := ss.GetMasterX().Get(&version, "SELECT Version FROM db_migrations ORDER BY Version DESC LIMIT 1"); err != nil {
|
||||
if err := ss.GetMaster().Get(&version, "SELECT Version FROM db_migrations ORDER BY Version DESC LIMIT 1"); err != nil {
|
||||
return 0, errors.Wrap(err, "unable to select from db_migrations")
|
||||
}
|
||||
return version, nil
|
||||
@@ -1291,7 +1291,7 @@ func (ss *SqlStore) GetDBSchemaVersion() (int, error) {
|
||||
|
||||
func (ss *SqlStore) GetAppliedMigrations() ([]model.AppliedMigration, error) {
|
||||
migrations := []model.AppliedMigration{}
|
||||
if err := ss.GetMasterX().Select(&migrations, "SELECT Version, Name FROM db_migrations ORDER BY Version DESC"); err != nil {
|
||||
if err := ss.GetMaster().Select(&migrations, "SELECT Version, Name FROM db_migrations ORDER BY Version DESC"); err != nil {
|
||||
return nil, errors.Wrap(err, "unable to select from db_migrations")
|
||||
}
|
||||
|
||||
@@ -1303,7 +1303,7 @@ func (ss *SqlStore) determineMaxColumnSize(tableName, columnName string) (int, e
|
||||
ss.getQueryPlaceholder()
|
||||
|
||||
if ss.DriverName() == model.DatabaseDriverPostgres {
|
||||
if err := ss.GetReplicaX().Get(&columnSizeBytes, `
|
||||
if err := ss.GetReplica().Get(&columnSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(character_maximum_length, 0)
|
||||
FROM
|
||||
@@ -1316,7 +1316,7 @@ func (ss *SqlStore) determineMaxColumnSize(tableName, columnName string) (int, e
|
||||
return 0, err
|
||||
}
|
||||
} else if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
if err := ss.GetReplicaX().Get(&columnSizeBytes, `
|
||||
if err := ss.GetReplica().Get(&columnSizeBytes, `
|
||||
SELECT
|
||||
COALESCE(CHARACTER_MAXIMUM_LENGTH, 0)
|
||||
FROM
|
||||
|
||||
Ссылка в новой задаче
Block a user