mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-15 10:43:21 +02:00
last_pull_sync_success -> mirror entity
This commit is contained in:
parent
f95b359c30
commit
b88d7a8469
@ -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 repository", v1_27.AddLastPullSyncSuccessUnixToRepository),
|
||||
newMigration(332, "Add last_pull_sync_success_unix to mirror", v1_27.AddLastPullSyncSuccessUnixToMirror),
|
||||
}
|
||||
return preparedMigrations
|
||||
}
|
||||
|
||||
@ -9,19 +9,19 @@ import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
type repositoryWithLastPullSyncSuccessUnix struct {
|
||||
type mirrorWithLastPullSyncSuccessUnix struct {
|
||||
LastPullSyncSuccessUnix int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
func (repositoryWithLastPullSyncSuccessUnix) TableName() string {
|
||||
return "repository"
|
||||
func (mirrorWithLastPullSyncSuccessUnix) TableName() string {
|
||||
return "mirror"
|
||||
}
|
||||
|
||||
func AddLastPullSyncSuccessUnixToRepository(x *xorm.Engine) error {
|
||||
if err := x.Sync(new(repositoryWithLastPullSyncSuccessUnix)); err != nil {
|
||||
func AddLastPullSyncSuccessUnixToMirror(x *xorm.Engine) error {
|
||||
if err := x.Sync(new(mirrorWithLastPullSyncSuccessUnix)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := x.Exec("UPDATE repository SET last_pull_sync_success_unix = ?", int64(timeutil.TimeStampNow()))
|
||||
_, err := x.Exec("UPDATE mirror SET last_pull_sync_success_unix = ?", int64(timeutil.TimeStampNow()))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -25,8 +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"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"`
|
||||
NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"`
|
||||
LastPullSyncSuccessUnix timeutil.TimeStamp `xorm:"INDEX"`
|
||||
|
||||
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
|
||||
LFSEndpoint string `xorm:"lfs_endpoint TEXT"`
|
||||
@ -98,6 +99,13 @@ 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)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteMirrorByRepoID deletes a mirror by repoID
|
||||
func DeleteMirrorByRepoID(ctx context.Context, repoID int64) error {
|
||||
_, err := db.GetEngine(ctx).Delete(&Mirror{RepoID: repoID})
|
||||
|
||||
@ -216,10 +216,9 @@ type Repository struct {
|
||||
// Avatar: ID(10-20)-md5(32) - must fit into 64 symbols
|
||||
Avatar string `xorm:"VARCHAR(64)"`
|
||||
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"`
|
||||
LastPullSyncSuccessUnix timeutil.TimeStamp `xorm:"INDEX"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
@ -34,14 +33,6 @@ func UpdateRepositoryUpdatedTime(ctx context.Context, repoID int64, updateTime t
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateRepositoryLastPullSyncSuccess updates a repository's last successful pull mirror sync time.
|
||||
func UpdateRepositoryLastPullSyncSuccess(ctx context.Context, repoID int64, syncTime timeutil.TimeStamp) error {
|
||||
_, err := db.GetEngine(ctx).ID(repoID).Cols("last_pull_sync_success_unix").NoAutoTime().Update(&Repository{
|
||||
LastPullSyncSuccessUnix: syncTime,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateRepositoryColsWithAutoTime updates repository's columns and the timestamp fields automatically
|
||||
func UpdateRepositoryColsWithAutoTime(ctx context.Context, repo *Repository, colName string, moreColNames ...string) error {
|
||||
_, err := db.GetEngine(ctx).ID(repo.ID).Cols(append([]string{colName}, moreColNames...)...).Update(repo)
|
||||
|
||||
@ -152,11 +152,13 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR
|
||||
|
||||
mirrorInterval := ""
|
||||
var mirrorUpdated time.Time
|
||||
var lastPullSyncSuccess 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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,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: repo.LastPullSyncSuccessUnix.AsTime(),
|
||||
LastPullSyncSuccess: lastPullSyncSuccess,
|
||||
MirrorInterval: mirrorInterval,
|
||||
MirrorUpdated: mirrorUpdated,
|
||||
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)
|
||||
return false
|
||||
}
|
||||
if err = repo_model.UpdateRepositoryLastPullSyncSuccess(ctx, m.Repo.ID, m.UpdatedUnix); err != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: failed to update repository last_pull_sync_success_unix: %v", m.Repo, err)
|
||||
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)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@ -94,8 +94,7 @@ func TestMirrorPull(t *testing.T) {
|
||||
assert.True(t, ok)
|
||||
|
||||
mirror := unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||
mirrorRepo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: mirrorRepo.ID})
|
||||
assert.Equal(t, mirror.UpdatedUnix, mirrorRepo.LastPullSyncSuccessUnix)
|
||||
assert.Equal(t, mirror.UpdatedUnix, mirror.LastPullSyncSuccessUnix)
|
||||
|
||||
// actually there is a tag in the source repo, so after "sync", that tag will also come into the mirror
|
||||
initCount++
|
||||
@ -115,14 +114,14 @@ func TestMirrorPull(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, initCount, count)
|
||||
|
||||
mirrorRepo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: mirrorRepo.ID})
|
||||
lastPullSyncSuccess := mirrorRepo.LastPullSyncSuccessUnix
|
||||
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||
lastPullSyncSuccess := mirror.LastPullSyncSuccessUnix
|
||||
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||
assert.NoError(t, mirror_service.UpdateAddress(ctx, mirror, repoPath+"-missing"))
|
||||
|
||||
ok = mirror_service.SyncPullMirror(ctx, mirrorRepo.ID)
|
||||
assert.False(t, ok)
|
||||
|
||||
mirrorRepo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: mirrorRepo.ID})
|
||||
assert.Equal(t, lastPullSyncSuccess, mirrorRepo.LastPullSyncSuccessUnix)
|
||||
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
|
||||
assert.Equal(t, lastPullSyncSuccess, mirror.LastPullSyncSuccessUnix)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user