summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2018-02-23 08:27:09 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2018-02-22 18:27:09 -0600
commit845ba9d1537eb1012bb0d448265b5346ef14d2d3 (patch)
treeca6bceba1babdae79e8fdb3d63a05fabc048b975 /models
parente7cea9253530091be4e0073bfd9152f09cb5a40d (diff)
downloadgitea-845ba9d1537eb1012bb0d448265b5346ef14d2d3.tar.gz
gitea-845ba9d1537eb1012bb0d448265b5346ef14d2d3.zip
fix: if Mirrors repo no content is fetched, updated time should not b… (#3551)
* fix: if Mirrors repo no content is fetched, updated time should not be changed * fix: sync update time from mirror repo. * fix: one single session. * update comment. Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Diffstat (limited to 'models')
-rw-r--r--models/repo_mirror.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/models/repo_mirror.go b/models/repo_mirror.go
index 197889e19a..97fe2406c6 100644
--- a/models/repo_mirror.go
+++ b/models/repo_mirror.go
@@ -244,6 +244,8 @@ func MirrorUpdate() {
// SyncMirrors checks and syncs mirrors.
// TODO: sync more mirrors at same time.
func SyncMirrors() {
+ sess := x.NewSession()
+ defer sess.Close()
// Start listening on new sync requests.
for repoID := range MirrorQueue.Queue() {
log.Trace("SyncMirrors [repo_id: %v]", repoID)
@@ -260,10 +262,22 @@ func SyncMirrors() {
}
m.ScheduleNextUpdate()
- if err = UpdateMirror(m); err != nil {
+ if err = updateMirror(sess, m); err != nil {
log.Error(4, "UpdateMirror [%s]: %v", repoID, err)
continue
}
+
+ // Get latest commit date and update to current repository updated time
+ commitDate, err := git.GetLatestCommitTime(m.Repo.RepoPath())
+ if err != nil {
+ log.Error(2, "GetLatestCommitDate [%s]: %v", m.RepoID, err)
+ continue
+ }
+
+ if _, err = sess.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", commitDate.Unix(), m.RepoID); err != nil {
+ log.Error(2, "Update repository 'updated_unix' [%s]: %v", m.RepoID, err)
+ continue
+ }
}
}