From a9fa7c93c20a251a4eb3667fae4a02f2eb50bf20 Mon Sep 17 00:00:00 2001 From: pomidorry Date: Wed, 6 May 2026 23:06:53 +0300 Subject: [PATCH] last_sync --- models/migrations/migrations.go | 2 +- models/migrations/v1_27/v332.go | 13 +++++-------- models/repo/mirror.go | 10 +++++----- modules/structs/repo.go | 2 +- services/convert/repository.go | 6 +++--- services/mirror/mirror_pull.go | 2 +- templates/swagger/v1_json.tmpl | 4 ++-- templates/swagger/v1_openapi3_json.tmpl | 4 ++-- tests/integration/mirror_pull_test.go | 6 +++--- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 4a7f27e938..c1d247bc41 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_mirror_sync_unix to mirror", v1_27.AddLastMirrorSyncUnixToMirror), + newMigration(332, "Add last_sync_unix to mirror", v1_27.AddLastSyncUnixToMirror), } return preparedMigrations } diff --git a/models/migrations/v1_27/v332.go b/models/migrations/v1_27/v332.go index 7840d26690..ec9320e8f6 100644 --- a/models/migrations/v1_27/v332.go +++ b/models/migrations/v1_27/v332.go @@ -5,17 +5,14 @@ package v1_27 import "xorm.io/xorm" -type mirrorWithLastMirrorSyncUnix struct { - LastMirrorSyncUnix int64 `xorm:"INDEX"` +type mirrorWithLastSyncUnix struct { + LastSyncUnix int64 `xorm:"last_sync_unix INDEX"` } -func (mirrorWithLastMirrorSyncUnix) TableName() string { +func (mirrorWithLastSyncUnix) TableName() string { return "mirror" } -func AddLastMirrorSyncUnixToMirror(x *xorm.Engine) error { - if err := x.Sync(new(mirrorWithLastMirrorSyncUnix)); err != nil { - return err - } - return nil +func AddLastSyncUnixToMirror(x *xorm.Engine) error { + return x.Sync(new(mirrorWithLastSyncUnix)) } diff --git a/models/repo/mirror.go b/models/repo/mirror.go index 7a509851e5..9bf4fedd31 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"` - LastMirrorSyncUnix timeutil.TimeStamp `xorm:"INDEX"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"` + NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"` + LastSyncUnix timeutil.TimeStamp `xorm:"last_sync_unix INDEX"` LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"` LFSEndpoint string `xorm:"lfs_endpoint TEXT"` @@ -101,8 +101,8 @@ func TouchMirror(ctx context.Context, m *Mirror) error { // 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) + m.LastSyncUnix = syncTime + _, err := db.GetEngine(ctx).ID(m.ID).Cols("last_sync_unix").NoAutoTime().Update(m) return err } diff --git a/modules/structs/repo.go b/modules/structs/repo.go index ab01060ab1..626c35f9e4 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -127,7 +127,7 @@ type Repository struct { // swagger:strfmt date-time MirrorUpdated time.Time `json:"mirror_updated"` // swagger:strfmt date-time - LastMirrorSync time.Time `json:"last_mirror_sync"` + LastSync time.Time `json:"last_sync"` RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"` Topics []string `json:"topics"` Licenses []string `json:"licenses"` diff --git a/services/convert/repository.go b/services/convert/repository.go index 1749b7410b..1976a78e1b 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 lastMirrorSync time.Time + var lastSync time.Time if repo.IsMirror { pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID) if err == nil { mirrorInterval = pullMirror.Interval.String() mirrorUpdated = pullMirror.UpdatedUnix.AsTime() - lastMirrorSync = pullMirror.LastMirrorSyncUnix.AsTime() + lastSync = pullMirror.LastSyncUnix.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, - LastMirrorSync: lastMirrorSync, + LastSync: lastSync, MirrorInterval: mirrorInterval, MirrorUpdated: mirrorUpdated, RepoTransfer: transfer, diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 757e807468..76f2c4b683 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -420,7 +420,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { return false } 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) + log.Error("SyncMirrors [repo: %-v]: failed to update mirror last_sync_unix: %v", m.Repo, err) return false } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index e80f95c9db..697999c0d1 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -29020,10 +29020,10 @@ "type": "string", "x-go-name": "LanguagesURL" }, - "last_mirror_sync": { + "last_sync": { "type": "string", "format": "date-time", - "x-go-name": "LastMirrorSync" + "x-go-name": "LastSync" }, "licenses": { "type": "array", diff --git a/templates/swagger/v1_openapi3_json.tmpl b/templates/swagger/v1_openapi3_json.tmpl index 640804922f..bacb1f8821 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_mirror_sync": { + "last_sync": { "format": "date-time", "type": "string", - "x-go-name": "LastMirrorSync" + "x-go-name": "LastSync" }, "licenses": { "items": { diff --git a/tests/integration/mirror_pull_test.go b/tests/integration/mirror_pull_test.go index 1e3afb70d6..85d44d492b 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.LastMirrorSyncUnix) + assert.Equal(t, mirror.UpdatedUnix, mirror.LastSyncUnix) // 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}) - lastMirrorSync := mirror.LastMirrorSyncUnix + lastMirrorSync := mirror.LastSyncUnix 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, lastMirrorSync, mirror.LastMirrorSyncUnix) + assert.Equal(t, lastMirrorSync, mirror.LastSyncUnix) }