Skip to content

Commit

Permalink
Refactor the code
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0443 committed Dec 16, 2024
1 parent b4ea9ac commit 7ad0f48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
26 changes: 10 additions & 16 deletions internal/mysql/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,21 @@ func (n *Node) traceQuery(query string, arg interface{}, result interface{}, err
}

func IsGtidQuery(query string) bool {
if query == DefaultQueries[queryGTIDExecuted] {
return true
}

if strings.HasPrefix(
query,
UtilityQueries[querySlaveStatus],
) {
return true
}

if strings.HasPrefix(
query,
UtilityQueries[queryReplicaStatus],
) {
return true
for _, gtidQuery := range GtidQueries {
if strings.HasPrefix(query, gtidQuery) {
return true
}
}

return false
}

var GtidQueries = []string{
DefaultQueries[queryGTIDExecuted],
strings.ReplaceAll(DefaultQueries[querySlaveStatus], ":channel", "''"),
strings.ReplaceAll(DefaultQueries[queryReplicaStatus], ":channel", ""),
}

//nolint:unparam
func (n *Node) queryRow(queryName string, arg interface{}, result interface{}) error {
return n.queryRowWithTimeout(queryName, arg, result, n.config.DBTimeout)
Expand Down
7 changes: 0 additions & 7 deletions internal/mysql/queries.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mysql

import "strings"

const (
queryPing = "ping"
querySlaveStatus = "slave_status"
Expand Down Expand Up @@ -145,8 +143,3 @@ var DefaultQueries = map[string]string{
)
ON DUPLICATE KEY UPDATE ts = CURRENT_TIMESTAMP(3)`,
}

var UtilityQueries = map[string]string{
querySlaveStatus: strings.ReplaceAll(DefaultQueries[querySlaveStatus], ":channel", ""),
queryReplicaStatus: strings.ReplaceAll(DefaultQueries[queryReplicaStatus], ":channel", ""),
}

0 comments on commit 7ad0f48

Please sign in to comment.