mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-03 08:30:46 +00:00
refactor: only update sync status columns when syncing push mirror (#39517)
`UpdatePushMirror` used `AllCols()`, so a sync could overwrite columns changed concurrently (e.g. `interval`) with stale values. It now updates only `last_update` and `last_error`, and is renamed to `UpdatePushMirrorSyncStatus` to match. Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 5) <noreply@anthropic.com>
This commit is contained in:
@@ -78,13 +78,13 @@ func (m *PushMirror) GetRemoteName() string {
|
||||
return m.RemoteName
|
||||
}
|
||||
|
||||
// UpdatePushMirror updates the push-mirror
|
||||
func UpdatePushMirror(ctx context.Context, m *PushMirror) error {
|
||||
_, err := db.GetEngine(ctx).ID(m.ID).AllCols().Update(m)
|
||||
// UpdatePushMirrorSyncStatus updates the sync status (last update time and last error) of the push-mirror
|
||||
func UpdatePushMirrorSyncStatus(ctx context.Context, m *PushMirror) error {
|
||||
_, err := db.GetEngine(ctx).ID(m.ID).Cols("last_update", "last_error").Update(m)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdatePushMirrorInterval updates the push-mirror
|
||||
// UpdatePushMirrorInterval updates the sync interval of the push-mirror
|
||||
func UpdatePushMirrorInterval(ctx context.Context, m *PushMirror) error {
|
||||
_, err := db.GetEngine(ctx).ID(m.ID).Cols("interval").Update(m)
|
||||
return err
|
||||
|
||||
@@ -109,8 +109,8 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool {
|
||||
|
||||
m.LastUpdateUnix = timeutil.TimeStampNow()
|
||||
|
||||
if err := repo_model.UpdatePushMirror(ctx, m); err != nil {
|
||||
log.Error("UpdatePushMirror [%d]: %v", m.ID, err)
|
||||
if err := repo_model.UpdatePushMirrorSyncStatus(ctx, m); err != nil {
|
||||
log.Error("UpdatePushMirrorSyncStatus [%d]: %v", m.ID, err)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
|
||||
|
||||
ok := mirror_service.SyncPushMirror(t.Context(), mirrors[0].ID)
|
||||
assert.True(t, ok)
|
||||
assert.NotZero(t, unittest.AssertExistsAndLoadBean(t, &repo_model.PushMirror{ID: mirrors[0].ID}).LastUpdateUnix)
|
||||
|
||||
srcGitRepo, err := git.OpenRepository(t.Context(), srcRepo)
|
||||
assert.NoError(t, err)
|
||||
@@ -74,6 +75,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
|
||||
|
||||
defer test.MockVariableValue(&setting.Migrations.AllowedHostList, "")()
|
||||
assert.False(t, mirror_service.SyncPushMirror(t.Context(), mirrors[0].ID))
|
||||
assert.NotEmpty(t, unittest.AssertExistsAndLoadBean(t, &repo_model.PushMirror{ID: mirrors[0].ID}).LastError)
|
||||
|
||||
// Cleanup
|
||||
assert.True(t, doRemovePushMirror(t, session, user.Name, srcRepo.Name, mirrors[0].ID))
|
||||
|
||||
Reference in New Issue
Block a user