mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-13 17:35:18 +02:00
last_sync
This commit is contained in:
parent
8177745b13
commit
a9fa7c93c2
@ -409,7 +409,7 @@ func prepareMigrationTasks() []*migration {
|
|||||||
// Gitea 1.26.0 ends at migration ID number 330 (database version 331)
|
// 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(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
|
return preparedMigrations
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,17 +5,14 @@ package v1_27
|
|||||||
|
|
||||||
import "xorm.io/xorm"
|
import "xorm.io/xorm"
|
||||||
|
|
||||||
type mirrorWithLastMirrorSyncUnix struct {
|
type mirrorWithLastSyncUnix struct {
|
||||||
LastMirrorSyncUnix int64 `xorm:"INDEX"`
|
LastSyncUnix int64 `xorm:"last_sync_unix INDEX"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mirrorWithLastMirrorSyncUnix) TableName() string {
|
func (mirrorWithLastSyncUnix) TableName() string {
|
||||||
return "mirror"
|
return "mirror"
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddLastMirrorSyncUnixToMirror(x *xorm.Engine) error {
|
func AddLastSyncUnixToMirror(x *xorm.Engine) error {
|
||||||
if err := x.Sync(new(mirrorWithLastMirrorSyncUnix)); err != nil {
|
return x.Sync(new(mirrorWithLastSyncUnix))
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,9 +25,9 @@ type Mirror struct {
|
|||||||
Interval time.Duration
|
Interval time.Duration
|
||||||
EnablePrune bool `xorm:"NOT NULL DEFAULT true"`
|
EnablePrune bool `xorm:"NOT NULL DEFAULT true"`
|
||||||
|
|
||||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"`
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"`
|
||||||
NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"`
|
NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"`
|
||||||
LastMirrorSyncUnix timeutil.TimeStamp `xorm:"INDEX"`
|
LastSyncUnix timeutil.TimeStamp `xorm:"last_sync_unix INDEX"`
|
||||||
|
|
||||||
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
|
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
|
||||||
LFSEndpoint string `xorm:"lfs_endpoint TEXT"`
|
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.
|
// UpdateMirrorLastSyncTime updates the mirror's last successful sync time.
|
||||||
func UpdateMirrorLastSyncTime(ctx context.Context, m *Mirror, syncTime timeutil.TimeStamp) error {
|
func UpdateMirrorLastSyncTime(ctx context.Context, m *Mirror, syncTime timeutil.TimeStamp) error {
|
||||||
m.LastMirrorSyncUnix = syncTime
|
m.LastSyncUnix = syncTime
|
||||||
_, err := db.GetEngine(ctx).ID(m.ID).Cols("last_mirror_sync_unix").NoAutoTime().Update(m)
|
_, err := db.GetEngine(ctx).ID(m.ID).Cols("last_sync_unix").NoAutoTime().Update(m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -127,7 +127,7 @@ type Repository struct {
|
|||||||
// swagger:strfmt date-time
|
// swagger:strfmt date-time
|
||||||
MirrorUpdated time.Time `json:"mirror_updated"`
|
MirrorUpdated time.Time `json:"mirror_updated"`
|
||||||
// swagger:strfmt date-time
|
// swagger:strfmt date-time
|
||||||
LastMirrorSync time.Time `json:"last_mirror_sync"`
|
LastSync time.Time `json:"last_sync"`
|
||||||
RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"`
|
RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"`
|
||||||
Topics []string `json:"topics"`
|
Topics []string `json:"topics"`
|
||||||
Licenses []string `json:"licenses"`
|
Licenses []string `json:"licenses"`
|
||||||
|
|||||||
@ -152,13 +152,13 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR
|
|||||||
|
|
||||||
mirrorInterval := ""
|
mirrorInterval := ""
|
||||||
var mirrorUpdated time.Time
|
var mirrorUpdated time.Time
|
||||||
var lastMirrorSync time.Time
|
var lastSync time.Time
|
||||||
if repo.IsMirror {
|
if repo.IsMirror {
|
||||||
pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
|
pullMirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mirrorInterval = pullMirror.Interval.String()
|
mirrorInterval = pullMirror.Interval.String()
|
||||||
mirrorUpdated = pullMirror.UpdatedUnix.AsTime()
|
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,
|
DefaultTargetBranch: defaultTargetBranch,
|
||||||
AvatarURL: repo.AvatarLink(ctx),
|
AvatarURL: repo.AvatarLink(ctx),
|
||||||
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
|
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
|
||||||
LastMirrorSync: lastMirrorSync,
|
LastSync: lastSync,
|
||||||
MirrorInterval: mirrorInterval,
|
MirrorInterval: mirrorInterval,
|
||||||
MirrorUpdated: mirrorUpdated,
|
MirrorUpdated: mirrorUpdated,
|
||||||
RepoTransfer: transfer,
|
RepoTransfer: transfer,
|
||||||
|
|||||||
@ -420,7 +420,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if err = repo_model.UpdateMirrorLastSyncTime(ctx, m, m.UpdatedUnix); err != nil {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
templates/swagger/v1_json.tmpl
generated
4
templates/swagger/v1_json.tmpl
generated
@ -29020,10 +29020,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LanguagesURL"
|
"x-go-name": "LanguagesURL"
|
||||||
},
|
},
|
||||||
"last_mirror_sync": {
|
"last_sync": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
"x-go-name": "LastMirrorSync"
|
"x-go-name": "LastSync"
|
||||||
},
|
},
|
||||||
"licenses": {
|
"licenses": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
|||||||
@ -9273,10 +9273,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LanguagesURL"
|
"x-go-name": "LanguagesURL"
|
||||||
},
|
},
|
||||||
"last_mirror_sync": {
|
"last_sync": {
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LastMirrorSync"
|
"x-go-name": "LastSync"
|
||||||
},
|
},
|
||||||
"licenses": {
|
"licenses": {
|
||||||
"items": {
|
"items": {
|
||||||
|
|||||||
@ -94,7 +94,7 @@ func TestMirrorPull(t *testing.T) {
|
|||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
|
|
||||||
mirror := unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
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
|
// actually there is a tag in the source repo, so after "sync", that tag will also come into the mirror
|
||||||
initCount++
|
initCount++
|
||||||
@ -115,7 +115,7 @@ func TestMirrorPull(t *testing.T) {
|
|||||||
assert.Equal(t, initCount, count)
|
assert.Equal(t, initCount, count)
|
||||||
|
|
||||||
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
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})
|
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||||
assert.NoError(t, mirror_service.UpdateAddress(ctx, mirror, repoPath+"-missing"))
|
assert.NoError(t, mirror_service.UpdateAddress(ctx, mirror, repoPath+"-missing"))
|
||||||
|
|
||||||
@ -123,5 +123,5 @@ func TestMirrorPull(t *testing.T) {
|
|||||||
assert.False(t, ok)
|
assert.False(t, ok)
|
||||||
|
|
||||||
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||||
assert.Equal(t, lastMirrorSync, mirror.LastMirrorSyncUnix)
|
assert.Equal(t, lastMirrorSync, mirror.LastSyncUnix)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user