Skip to content

Commit

Permalink
Merge pull request #678 from linthan/fixconfigurationupdate
Browse files Browse the repository at this point in the history
fix: 防止修改锁状态 同时修改了其他的数据
  • Loading branch information
sysulq authored Aug 15, 2024
2 parents 7f67919 + efbe566 commit 5bfe804
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-version: 1.19

- name: docker-compose
run: docker-compose -f tests/docker-compose.yaml up -d
run: docker compose -f tests/docker-compose.yaml up -d

- uses: actions/cache@v3
with:
Expand Down
35 changes: 0 additions & 35 deletions internal/pkg/service/codeplatform/codeplatform_test.go

This file was deleted.

11 changes: 7 additions & 4 deletions internal/pkg/service/confgov2/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TryLock(uid, configId uint) (err error) {
config.LockUid = uid
now := time.Now()
config.LockAt = &now
err = tx.Save(&config).Error
err = tx.Table("configuration").Where("id = ?", config.ID).Updates(map[string]interface{}{"lock_uid": config.LockUid,
"lock_at": config.LockAt}).Error
if err != nil {
tx.Rollback()
return errors.Wrap(err, "获取编辑锁失败")
Expand All @@ -59,7 +60,8 @@ func Unlock(uid, configId uint) (err error) {

config.LockUid = 0
config.LockAt = nil
err = tx.Save(&config).Error
err = tx.Table("configuration").Where("id = ?", config.ID).Updates(map[string]interface{}{"lock_uid": config.LockUid,
"lock_at": config.LockAt}).Error
if err != nil {
tx.Rollback()
return errors.Wrap(err, "释放编辑锁失败")
Expand All @@ -68,7 +70,7 @@ func Unlock(uid, configId uint) (err error) {
return tx.Commit().Error
}

//clearLockPeriodically 定期清除编辑锁
// clearLockPeriodically 定期清除编辑锁
func clearLockPeriodically() {
var configs []db.Configuration

Expand All @@ -88,7 +90,8 @@ func clearLockPeriodically() {
for _, config := range configs {
config.LockAt = nil
config.LockUid = 0
tx.Save(&config)
tx.Table("configuration").Where("id = ?", config.ID).Updates(map[string]interface{}{"lock_uid": config.LockUid,
"lock_at": config.LockAt})
}
}
tx.Commit()
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
ports:
- 8080:8080
etcd:
image: "quay.io/coreos/etcd:v3.3"
image: "quay.io/coreos/etcd:v3.5.15"
environment:
ETCD_ADVERTISE_CLIENT_URLS: "http://0.0.0.0:2379"
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
Expand Down

0 comments on commit 5bfe804

Please sign in to comment.