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:
Lunny Xiao
2026-10-02 12:28:51 -07:00
committed by GitHub
parent cf89ecd887
commit 6dad3ad43d
3 changed files with 8 additions and 6 deletions
+4 -4
View File
@@ -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
+2 -2
View File
@@ -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
}
+2
View File
@@ -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))