Extract binary_parameters handle logic into public methods for external use (#20043)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2576556c8b
Коммит
6608f3a9ca
@@ -35,7 +35,7 @@ func (jss SqlJobStore) Save(job *model.Job) (*model.Job, error) {
|
|||||||
return nil, errors.Wrap(err, "failed marshalling job data")
|
return nil, errors.Wrap(err, "failed marshalling job data")
|
||||||
}
|
}
|
||||||
if jss.IsBinaryParamEnabled() {
|
if jss.IsBinaryParamEnabled() {
|
||||||
jsonData = jss.AppendBinaryFlag(jsonData)
|
jsonData = AppendBinaryFlag(jsonData)
|
||||||
}
|
}
|
||||||
query := jss.getQueryBuilder().
|
query := jss.getQueryBuilder().
|
||||||
Insert("Jobs").
|
Insert("Jobs").
|
||||||
@@ -60,7 +60,7 @@ func (jss SqlJobStore) UpdateOptimistically(job *model.Job, currentStatus string
|
|||||||
return false, errors.Wrap(jsonErr, "failed to encode job's data to JSON")
|
return false, errors.Wrap(jsonErr, "failed to encode job's data to JSON")
|
||||||
}
|
}
|
||||||
if jss.IsBinaryParamEnabled() {
|
if jss.IsBinaryParamEnabled() {
|
||||||
dataJSON = jss.AppendBinaryFlag(dataJSON)
|
dataJSON = AppendBinaryFlag(dataJSON)
|
||||||
}
|
}
|
||||||
query, args, err := jss.getQueryBuilder().
|
query, args, err := jss.getQueryBuilder().
|
||||||
Update("Jobs").
|
Update("Jobs").
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (s SqlLinkMetadataStore) Save(metadata *model.LinkMetadata) (*model.LinkMet
|
|||||||
return nil, errors.Wrap(err, "could not serialize metadataBytes to JSON")
|
return nil, errors.Wrap(err, "could not serialize metadataBytes to JSON")
|
||||||
}
|
}
|
||||||
if s.IsBinaryParamEnabled() {
|
if s.IsBinaryParamEnabled() {
|
||||||
metadataBytes = s.AppendBinaryFlag(metadataBytes)
|
metadataBytes = AppendBinaryFlag(metadataBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
query := s.getQueryBuilder().
|
query := s.getQueryBuilder().
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (me SqlSessionStore) Save(session *model.Session) (*model.Session, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if me.IsBinaryParamEnabled() {
|
if me.IsBinaryParamEnabled() {
|
||||||
jsonProps = me.AppendBinaryFlag(jsonProps)
|
jsonProps = AppendBinaryFlag(jsonProps)
|
||||||
}
|
}
|
||||||
|
|
||||||
query, args, err := me.getQueryBuilder().
|
query, args, err := me.getQueryBuilder().
|
||||||
@@ -268,7 +268,7 @@ func (me SqlSessionStore) UpdateProps(session *model.Session) error {
|
|||||||
return errors.Wrap(err, "failed marshalling session props")
|
return errors.Wrap(err, "failed marshalling session props")
|
||||||
}
|
}
|
||||||
if me.IsBinaryParamEnabled() {
|
if me.IsBinaryParamEnabled() {
|
||||||
jsonProps = me.AppendBinaryFlag(jsonProps)
|
jsonProps = AppendBinaryFlag(jsonProps)
|
||||||
}
|
}
|
||||||
query, args, err := me.getQueryBuilder().
|
query, args, err := me.getQueryBuilder().
|
||||||
Update("Sessions").
|
Update("Sessions").
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
dbsql "database/sql"
|
dbsql "database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -338,22 +337,13 @@ func (ss *SqlStore) computeBinaryParam() (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
url, err := url.Parse(*ss.settings.DataSource)
|
return DSNHasBinaryParam(*ss.settings.DataSource)
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return url.Query().Get("binary_parameters") == "yes", nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *SqlStore) IsBinaryParamEnabled() bool {
|
func (ss *SqlStore) IsBinaryParamEnabled() bool {
|
||||||
return ss.isBinaryParam
|
return ss.isBinaryParam
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendBinaryFlag updates the byte slice to work using binary_parameters=yes.
|
|
||||||
func (ss *SqlStore) AppendBinaryFlag(buf []byte) []byte {
|
|
||||||
return append([]byte{0x01}, buf...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ss *SqlStore) getCurrentSchemaVersion() (string, error) {
|
func (ss *SqlStore) getCurrentSchemaVersion() (string, error) {
|
||||||
var version string
|
var version string
|
||||||
err := ss.GetMasterX().Get(&version, "SELECT Value FROM Systems WHERE Name='Version'")
|
err := ss.GetMasterX().Get(&version, "SELECT Value FROM Systems WHERE Name='Version'")
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ func (us SqlUserStore) UpdateNotifyProps(userID string, props map[string]string)
|
|||||||
return errors.Wrap(err, "failed marshalling session props")
|
return errors.Wrap(err, "failed marshalling session props")
|
||||||
}
|
}
|
||||||
if us.IsBinaryParamEnabled() {
|
if us.IsBinaryParamEnabled() {
|
||||||
buf = us.AppendBinaryFlag(buf)
|
buf = AppendBinaryFlag(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := us.GetMasterX().Exec(`UPDATE Users
|
if _, err := us.GetMasterX().Exec(`UPDATE Users
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package sqlstore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
@@ -156,3 +157,16 @@ func (l *morphWriter) Write(in []byte) (int, error) {
|
|||||||
mlog.Debug(string(in))
|
mlog.Debug(string(in))
|
||||||
return len(in), nil
|
return len(in), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DSNHasBinaryParam(dsn string) (bool, error) {
|
||||||
|
url, err := url.Parse(dsn)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return url.Query().Get("binary_parameters") == "yes", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppendBinaryFlag updates the byte slice to work using binary_parameters=yes.
|
||||||
|
func AppendBinaryFlag(buf []byte) []byte {
|
||||||
|
return append([]byte{0x01}, buf...)
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user