last_pull_sync and time to zero

This commit is contained in:
pomidorry committed 2026-05-06 22:56:02 +03:00
1 parent b88d7a8469
commit 8177745b13
9 files changed
+32 -38

No files matched your search

+1 -1
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_pull_sync_success_unix to mirror", v1_27.AddLastPullSyncSuccessUnixToMirror),
newMigration(332, "Add last_mirror_sync_unix to mirror", v1_27.AddLastMirrorSyncUnixToMirror),
}
return preparedMigrations
}
+7 -13
View File
@@ -3,25 +3,19 @@
package v1_27
import (
"code.gitea.io/gitea/modules/timeutil"
import "xorm.io/xorm"
"xorm.io/xorm"
)
type mirrorWithLastPullSyncSuccessUnix struct {
LastPullSyncSuccessUnix int64 `xorm:"INDEX"`
type mirrorWithLastMirrorSyncUnix struct {
LastMirrorSyncUnix int64 `xorm:"INDEX"`
}
func (mirrorWithLastPullSyncSuccessUnix) TableName() string {
func (mirrorWithLastMirrorSyncUnix) TableName() string {
return "mirror"
}
func AddLastPullSyncSuccessUnixToMirror(x *xorm.Engine) error {
if err := x.Sync(new(mirrorWithLastPullSyncSuccessUnix)); err != nil {
func AddLastMirrorSyncUnixToMirror(x *xorm.Engine) error {
if err := x.Sync(new(mirrorWithLastMirrorSyncUnix)); err != nil {
return err
}
_, err := x.Exec("UPDATE mirror SET last_pull_sync_success_unix = ?", int64(timeutil.TimeStampNow()))
return err
return nil
}
+7 -7
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"`
LastPullSyncSuccessUnix timeutil.TimeStamp `xorm:"INDEX"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"`
NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"`
LastMirrorSyncUnix timeutil.TimeStamp `xorm:"INDEX"`
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
LFSEndpoint string `xorm:"lfs_endpoint TEXT"`
@@ -99,10 +99,10 @@ 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)
// 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)
return err
}
+5 -5
View File
@@ -125,12 +125,12 @@ type Repository struct {
// ObjectFormatName of the underlying git repository
ObjectFormatName ObjectFormatName `json:"object_format_name"`
// swagger:strfmt date-time
MirrorUpdated time.Time `json:"mirror_updated"`
MirrorUpdated time.Time `json:"mirror_updated"`
// swagger:strfmt date-time
LastPullSyncSuccess time.Time `json:"last_pull_sync_success"`
RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"`
Topics []string `json:"topics"`
Licenses []string `json:"licenses"`
LastMirrorSync time.Time `json:"last_mirror_sync"`
RepoTransfer *RepoTransfer `json:"repo_transfer,omitempty"`
Topics []string `json:"topics"`
Licenses []string `json:"licenses"`
}
// CreateRepoOption options when creating repository
+3 -3
View File
@@ -152,13 +152,13 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR
mirrorInterval := ""
var mirrorUpdated time.Time
var lastPullSyncSuccess time.Time
var lastMirrorSync 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()
lastMirrorSync = pullMirror.LastMirrorSyncUnix.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,
LastPullSyncSuccess: lastPullSyncSuccess,
LastMirrorSync: lastMirrorSync,
MirrorInterval: mirrorInterval,
MirrorUpdated: mirrorUpdated,
RepoTransfer: transfer,
+2 -2
View File
@@ -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.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)
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)
return false
}
+2 -2
View File
@@ -29020,10 +29020,10 @@
"type": "string",
"x-go-name": "LanguagesURL"
},
"last_pull_sync_success": {
"last_mirror_sync": {
"type": "string",
"format": "date-time",
"x-go-name": "LastPullSyncSuccess"
"x-go-name": "LastMirrorSync"
},
"licenses": {
"type": "array",
+2 -2
View File
@@ -9273,10 +9273,10 @@
"type": "string",
"x-go-name": "LanguagesURL"
},
"last_pull_sync_success": {
"last_mirror_sync": {
"format": "date-time",
"type": "string",
"x-go-name": "LastPullSyncSuccess"
"x-go-name": "LastMirrorSync"
},
"licenses": {
"items": {
+3 -3
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.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
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})
lastPullSyncSuccess := mirror.LastPullSyncSuccessUnix
lastMirrorSync := mirror.LastMirrorSyncUnix
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, lastPullSyncSuccess, mirror.LastPullSyncSuccessUnix)
assert.Equal(t, lastMirrorSync, mirror.LastMirrorSyncUnix)
}