From 8177745b133d76fa9d77680333e77fe84df4643e Mon Sep 17 00:00:00 2001 From: pomidorry Date: Wed, 6 May 2026 22:56:02 +0300 Subject: [PATCH] last_pull_sync and time to zero --- models/migrations/migrations.go | 2 +- models/migrations/v1_27/v332.go | 20 +++++++------------- models/repo/mirror.go | 14 +++++++------- modules/structs/repo.go | 10 +++++----- services/convert/repository.go | 6 +++--- services/mirror/mirror_pull.go | 4 ++-- templates/swagger/v1_json.tmpl | 4 ++-- templates/swagger/v1_openapi3_json.tmpl | 4 ++-- tests/integration/mirror_pull_test.go | 6 +++--- 9 files changed, 32 insertions(+), 38 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index e44630253c..4a7f27e938 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -409,7 +409,7 @@ func prepareMigrationTasks() []*migration { // Gitea 1.26.0 ends at migration ID number 330 (database version 331) newMigration(331, "Add ActionRunAttempt model and related action fields", v1_27.AddActionRunAttemptModel), - newMigration(332, "Add last_pull_sync_success_unix to mirror", v1_27.AddLastPullSyncSuccessUnixToMirror), + newMigration(332, "Add last_mirror_sync_unix to mirror", v1_27.AddLastMirrorSyncUnixToMirror), } return preparedMigrations } diff --git a/models/migrations/v1_27/v332.go b/models/migrations/v1_27/v332.go index bf290f4fdf..7840d26690 100644 --- a/models/migrations/v1_27/v332.go +++ b/models/migrations/v1_27/v332.go @@ -3,25 +3,19 @@ package v1_27 -import ( - "code.gitea.io/gitea/modules/timeutil" +import "xorm.io/xorm" - "xorm.io/xorm" -) - -type mirrorWithLastPullSyncSuccessUnix struct { - LastPullSyncSuccessUnix int64 `xorm:"INDEX"` +type mirrorWithLastMirrorSyncUnix struct { + LastMirrorSyncUnix int64 `xorm:"INDEX"` } -func (mirrorWithLastPullSyncSuccessUnix) TableName() string { +func (mirrorWithLastMirrorSyncUnix) TableName() string { return "mirror" } -func AddLastPullSyncSuccessUnixToMirror(x *xorm.Engine) error { - if err := x.Sync(new(mirrorWithLastPullSyncSuccessUnix)); err != nil { +func AddLastMirrorSyncUnixToMirror(x *xorm.Engine) error { + if err := x.Sync(new(mirrorWithLastMirrorSyncUnix)); err != nil { return err } - - _, err := x.Exec("UPDATE mirror SET last_pull_sync_success_unix = ?", int64(timeutil.TimeStampNow())) - return err + return nil } diff --git a/models/repo/mirror.go b/models/repo/mirror.go index 7d27cf9707..7a509851e5 100644 --- a/models/repo/mirror.go +++ b/models/repo/mirror.go @@ -25,9 +25,9 @@ type Mirror struct { Interval time.Duration EnablePrune bool `xorm:"NOT NULL DEFAULT true"` - UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"` - NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"` - LastPullSyncSuccessUnix timeutil.TimeStamp `xorm:"INDEX"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"` + NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"` + LastMirrorSyncUnix timeutil.TimeStamp `xorm:"INDEX"` LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"` LFSEndpoint string `xorm:"lfs_endpoint TEXT"` @@ -99,10 +99,10 @@ func TouchMirror(ctx context.Context, m *Mirror) error { return err } -// UpdateMirrorLastPullSyncSuccess updates the mirror's last successful pull mirror sync time. -func UpdateMirrorLastPullSyncSuccess(ctx context.Context, m *Mirror, syncTime timeutil.TimeStamp) error { - m.LastPullSyncSuccessUnix = syncTime - _, err := db.GetEngine(ctx).ID(m.ID).Cols("last_pull_sync_success_unix").NoAutoTime().Update(m) +// UpdateMirrorLastSyncTime updates the mirror's last successful sync time. +func UpdateMirrorLastSyncTime(ctx context.Context, m *Mirror, syncTime timeutil.TimeStamp) error { + m.LastMirrorSyncUnix = syncTime + _, err := db.GetEngine(ctx).ID(m.ID).Cols("last_mirror_sync_unix").NoAutoTime().Update(m) return err } diff --git a/modules/structs/repo.go b/modules/structs/repo.go index 29c49146e9..ab01060ab1 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -125,12 +125,12 @@ type Repository struct { // ObjectFormatName of the underlying git repository ObjectFormatName ObjectFormatName `json:"object_format_name"` // swagger:strfmt date-time - MirrorUpdated time.Time `json:"mirror_updated"` + MirrorUpdated time.Time `json:"mirror_updated"` // swagger:strfmt date-time - LastPullSyncSuccess time.Time `json:"last_pull_sync_success"` - RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"` - Topics []string `json:"topics"` - Licenses []string `json:"licenses"` + LastMirrorSync time.Time `json:"last_mirror_sync"` + RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"` + Topics []string `json:"topics"` + Licenses []string `json:"licenses"` } // CreateRepoOption options when creating repository diff --git a/services/convert/repository.go b/services/convert/repository.go index eafb78d674..1749b7410b 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -152,13 +152,13 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR mirrorInterval := "" var mirrorUpdated time.Time - var lastPullSyncSuccess time.Time + var lastMirrorSync time.Time if repo.IsMirror { pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID) if err == nil { mirrorInterval = pullMirror.Interval.String() mirrorUpdated = pullMirror.UpdatedUnix.AsTime() - lastPullSyncSuccess = pullMirror.LastPullSyncSuccessUnix.AsTime() + lastMirrorSync = pullMirror.LastMirrorSyncUnix.AsTime() } } @@ -249,7 +249,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR DefaultTargetBranch: defaultTargetBranch, AvatarURL: repo.AvatarLink(ctx), Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate, - LastPullSyncSuccess: lastPullSyncSuccess, + LastMirrorSync: lastMirrorSync, MirrorInterval: mirrorInterval, MirrorUpdated: mirrorUpdated, RepoTransfer: transfer, diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index de72f8daab..757e807468 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -419,8 +419,8 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Error("SyncMirrors [repo: %-v]: unable to add repo to license updater queue: %v", m.Repo, err) return false } - if err = repo_model.UpdateMirrorLastPullSyncSuccess(ctx, m, m.UpdatedUnix); err != nil { - log.Error("SyncMirrors [repo: %-v]: failed to update mirror last_pull_sync_success_unix: %v", m.Repo, err) + if err = repo_model.UpdateMirrorLastSyncTime(ctx, m, m.UpdatedUnix); err != nil { + log.Error("SyncMirrors [repo: %-v]: failed to update mirror last_mirror_sync_unix: %v", m.Repo, err) return false } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 03fc6d7a46..e80f95c9db 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -29020,10 +29020,10 @@ "type": "string", "x-go-name": "LanguagesURL" }, - "last_pull_sync_success": { + "last_mirror_sync": { "type": "string", "format": "date-time", - "x-go-name": "LastPullSyncSuccess" + "x-go-name": "LastMirrorSync" }, "licenses": { "type": "array", diff --git a/templates/swagger/v1_openapi3_json.tmpl b/templates/swagger/v1_openapi3_json.tmpl index f43b01e1da..640804922f 100644 --- a/templates/swagger/v1_openapi3_json.tmpl +++ b/templates/swagger/v1_openapi3_json.tmpl @@ -9273,10 +9273,10 @@ "type": "string", "x-go-name": "LanguagesURL" }, - "last_pull_sync_success": { + "last_mirror_sync": { "format": "date-time", "type": "string", - "x-go-name": "LastPullSyncSuccess" + "x-go-name": "LastMirrorSync" }, "licenses": { "items": { diff --git a/tests/integration/mirror_pull_test.go b/tests/integration/mirror_pull_test.go index d9d798f2c1..1e3afb70d6 100644 --- a/tests/integration/mirror_pull_test.go +++ b/tests/integration/mirror_pull_test.go @@ -94,7 +94,7 @@ func TestMirrorPull(t *testing.T) { assert.True(t, ok) mirror := unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID}) - assert.Equal(t, mirror.UpdatedUnix, mirror.LastPullSyncSuccessUnix) + assert.Equal(t, mirror.UpdatedUnix, mirror.LastMirrorSyncUnix) // actually there is a tag in the source repo, so after "sync", that tag will also come into the mirror initCount++ @@ -115,7 +115,7 @@ func TestMirrorPull(t *testing.T) { assert.Equal(t, initCount, count) mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID}) - lastPullSyncSuccess := mirror.LastPullSyncSuccessUnix + lastMirrorSync := mirror.LastMirrorSyncUnix mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID}) assert.NoError(t, mirror_service.UpdateAddress(ctx, mirror, repoPath+"-missing")) @@ -123,5 +123,5 @@ func TestMirrorPull(t *testing.T) { assert.False(t, ok) mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID}) - assert.Equal(t, lastPullSyncSuccess, mirror.LastPullSyncSuccessUnix) + assert.Equal(t, lastMirrorSync, mirror.LastMirrorSyncUnix) }