0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-13 08:55:40 +02:00

last_sync

This commit is contained in:
pomidorry 2026-05-06 23:06:53 +03:00
parent 8177745b13
commit a9fa7c93c2
9 changed files with 23 additions and 26 deletions

View File

@ -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
}

View File

@ -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))
}

View File

@ -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
}

View File

@ -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"`

View File

@ -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,

View File

@ -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
}

View File

@ -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",

View File

@ -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": {

View File

@ -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)
}