mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-24 08:08:38 +00:00
Use session for ServerConfigSet to make it atomic (#4116)
This commit is contained in:
parent
41b2127e04
commit
4dd4d9755d
1 changed files with 13 additions and 4 deletions
|
@ -31,7 +31,13 @@ func (s storage) ServerConfigSet(key, value string) error {
|
||||||
Key: key,
|
Key: key,
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := s.engine.Count(config)
|
sess := s.engine.NewSession()
|
||||||
|
defer sess.Close()
|
||||||
|
if err := sess.Begin(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := sess.Count(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -39,12 +45,15 @@ func (s storage) ServerConfigSet(key, value string) error {
|
||||||
config.Value = value
|
config.Value = value
|
||||||
|
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
_, err := s.engine.Insert(config)
|
_, err = sess.Insert(config)
|
||||||
|
} else {
|
||||||
|
_, err = sess.Where("`key` = ?", config.Key).Cols("value").Update(config)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.engine.Where("`key` = ?", config.Key).Cols("value").Update(config)
|
return sess.Commit()
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storage) ServerConfigDelete(key string) error {
|
func (s storage) ServerConfigDelete(key string) error {
|
||||||
|
|
Loading…
Reference in a new issue