mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-16 01:47:25 +02:00
last_pull_sync and time to zero
This commit is contained in:
parent
b88d7a8469
commit
8177745b13
@ -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_pull_sync_success_unix to mirror", v1_27.AddLastPullSyncSuccessUnixToMirror),
|
newMigration(332, "Add last_mirror_sync_unix to mirror", v1_27.AddLastMirrorSyncUnixToMirror),
|
||||||
}
|
}
|
||||||
return preparedMigrations
|
return preparedMigrations
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,25 +3,19 @@
|
|||||||
|
|
||||||
package v1_27
|
package v1_27
|
||||||
|
|
||||||
import (
|
import "xorm.io/xorm"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
|
||||||
|
|
||||||
"xorm.io/xorm"
|
type mirrorWithLastMirrorSyncUnix struct {
|
||||||
)
|
LastMirrorSyncUnix int64 `xorm:"INDEX"`
|
||||||
|
|
||||||
type mirrorWithLastPullSyncSuccessUnix struct {
|
|
||||||
LastPullSyncSuccessUnix int64 `xorm:"INDEX"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mirrorWithLastPullSyncSuccessUnix) TableName() string {
|
func (mirrorWithLastMirrorSyncUnix) TableName() string {
|
||||||
return "mirror"
|
return "mirror"
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddLastPullSyncSuccessUnixToMirror(x *xorm.Engine) error {
|
func AddLastMirrorSyncUnixToMirror(x *xorm.Engine) error {
|
||||||
if err := x.Sync(new(mirrorWithLastPullSyncSuccessUnix)); err != nil {
|
if err := x.Sync(new(mirrorWithLastMirrorSyncUnix)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
_, err := x.Exec("UPDATE mirror SET last_pull_sync_success_unix = ?", int64(timeutil.TimeStampNow()))
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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"`
|
||||||
LastPullSyncSuccessUnix timeutil.TimeStamp `xorm:"INDEX"`
|
LastMirrorSyncUnix timeutil.TimeStamp `xorm:"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"`
|
||||||
@ -99,10 +99,10 @@ func TouchMirror(ctx context.Context, m *Mirror) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateMirrorLastPullSyncSuccess updates the mirror's last successful pull mirror sync time.
|
// UpdateMirrorLastSyncTime updates the mirror's last successful sync time.
|
||||||
func UpdateMirrorLastPullSyncSuccess(ctx context.Context, m *Mirror, syncTime timeutil.TimeStamp) error {
|
func UpdateMirrorLastSyncTime(ctx context.Context, m *Mirror, syncTime timeutil.TimeStamp) error {
|
||||||
m.LastPullSyncSuccessUnix = syncTime
|
m.LastMirrorSyncUnix = syncTime
|
||||||
_, err := db.GetEngine(ctx).ID(m.ID).Cols("last_pull_sync_success_unix").NoAutoTime().Update(m)
|
_, err := db.GetEngine(ctx).ID(m.ID).Cols("last_mirror_sync_unix").NoAutoTime().Update(m)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -125,12 +125,12 @@ type Repository struct {
|
|||||||
// ObjectFormatName of the underlying git repository
|
// ObjectFormatName of the underlying git repository
|
||||||
ObjectFormatName ObjectFormatName `json:"object_format_name"`
|
ObjectFormatName ObjectFormatName `json:"object_format_name"`
|
||||||
// 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
|
||||||
LastPullSyncSuccess time.Time `json:"last_pull_sync_success"`
|
LastMirrorSync time.Time `json:"last_mirror_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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRepoOption options when creating repository
|
// CreateRepoOption options when creating repository
|
||||||
|
|||||||
@ -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 lastPullSyncSuccess time.Time
|
var lastMirrorSync 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()
|
||||||
lastPullSyncSuccess = pullMirror.LastPullSyncSuccessUnix.AsTime()
|
lastMirrorSync = pullMirror.LastMirrorSyncUnix.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,
|
||||||
LastPullSyncSuccess: lastPullSyncSuccess,
|
LastMirrorSync: lastMirrorSync,
|
||||||
MirrorInterval: mirrorInterval,
|
MirrorInterval: mirrorInterval,
|
||||||
MirrorUpdated: mirrorUpdated,
|
MirrorUpdated: mirrorUpdated,
|
||||||
RepoTransfer: transfer,
|
RepoTransfer: transfer,
|
||||||
|
|||||||
@ -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)
|
log.Error("SyncMirrors [repo: %-v]: unable to add repo to license updater queue: %v", m.Repo, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if err = repo_model.UpdateMirrorLastPullSyncSuccess(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_pull_sync_success_unix: %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v]: failed to update mirror last_mirror_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_pull_sync_success": {
|
"last_mirror_sync": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
"x-go-name": "LastPullSyncSuccess"
|
"x-go-name": "LastMirrorSync"
|
||||||
},
|
},
|
||||||
"licenses": {
|
"licenses": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
|
|||||||
@ -9273,10 +9273,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LanguagesURL"
|
"x-go-name": "LanguagesURL"
|
||||||
},
|
},
|
||||||
"last_pull_sync_success": {
|
"last_mirror_sync": {
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LastPullSyncSuccess"
|
"x-go-name": "LastMirrorSync"
|
||||||
},
|
},
|
||||||
"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.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
|
// 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})
|
||||||
lastPullSyncSuccess := mirror.LastPullSyncSuccessUnix
|
lastMirrorSync := mirror.LastMirrorSyncUnix
|
||||||
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, lastPullSyncSuccess, mirror.LastPullSyncSuccessUnix)
|
assert.Equal(t, lastMirrorSync, mirror.LastMirrorSyncUnix)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user