sync: Don't pull repo when doing synchronization. Do it only on auto-sync
This commit is contained in:
parent
ac64db277a
commit
5fb85c22dc
@ -205,6 +205,14 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
|||||||
func autoSync(c *gin.Context) {
|
func autoSync(c *gin.Context) {
|
||||||
p := strings.Split(strings.TrimPrefix(c.Params.ByName("p"), "/"), "/")
|
p := strings.Split(strings.TrimPrefix(c.Params.ByName("p"), "/"), "/")
|
||||||
|
|
||||||
|
if !IsProductionEnv {
|
||||||
|
if err := sync.GlobalImporter.Sync(); err != nil {
|
||||||
|
log.Println("Unable to sync.GI.Sync:", err.Error())
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to perform the pull."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
themes, err := fic.GetThemes()
|
themes, err := fic.GetThemes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Unable to GetThemes:", err.Error())
|
log.Println("Unable to GetThemes:", err.Error())
|
||||||
|
@ -21,17 +21,11 @@ var oneThemeDeepSync sync.Mutex
|
|||||||
// DeepSyncProgress expose the progression of the depp synchronization (0 = 0%, 255 = 100%).
|
// DeepSyncProgress expose the progression of the depp synchronization (0 = 0%, 255 = 100%).
|
||||||
var DeepSyncProgress uint8
|
var DeepSyncProgress uint8
|
||||||
|
|
||||||
// avoidImporterSync checks if Sync should be called or not.
|
|
||||||
func avoidImporterSync() bool {
|
|
||||||
return DeepSyncProgress > 1 && DeepSyncProgress < 255
|
|
||||||
}
|
|
||||||
|
|
||||||
type SyncReport struct {
|
type SyncReport struct {
|
||||||
DateStart time.Time `json:"_started"`
|
DateStart time.Time `json:"_started"`
|
||||||
DateEnd time.Time `json:"_ended"`
|
DateEnd time.Time `json:"_ended"`
|
||||||
DateUpdated []time.Time `json:"_updated"`
|
DateUpdated []time.Time `json:"_updated"`
|
||||||
Regeneration []string `json:"_regeneration"`
|
Regeneration []string `json:"_regeneration"`
|
||||||
SyncError error `json:"_sync,omitempty"`
|
|
||||||
SyncId string `json:"_id,omitempty"`
|
SyncId string `json:"_id,omitempty"`
|
||||||
ThemesSync []string `json:"_themes,omitempty"`
|
ThemesSync []string `json:"_themes,omitempty"`
|
||||||
Themes map[string][]string `json:"themes"`
|
Themes map[string][]string `json:"themes"`
|
||||||
@ -116,10 +110,6 @@ func SyncDeep(i Importer) (errs SyncReport) {
|
|||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
if err := i.Sync(); err != nil {
|
|
||||||
errs.SyncError = err
|
|
||||||
}
|
|
||||||
|
|
||||||
errs.DateStart = startTime
|
errs.DateStart = startTime
|
||||||
exceptions, sterrs := SyncThemes(i)
|
exceptions, sterrs := SyncThemes(i)
|
||||||
for _, sterr := range sterrs {
|
for _, sterr := range sterrs {
|
||||||
@ -206,12 +196,6 @@ func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8, excep
|
|||||||
oneThemeDeepSync.Lock()
|
oneThemeDeepSync.Lock()
|
||||||
defer oneThemeDeepSync.Unlock()
|
defer oneThemeDeepSync.Unlock()
|
||||||
|
|
||||||
if !avoidImporterSync() {
|
|
||||||
if err := i.Sync(); err != nil {
|
|
||||||
errs = append(errs, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DeepSyncProgress = 3 + uint8(tid)*themeStep
|
DeepSyncProgress = 3 + uint8(tid)*themeStep
|
||||||
errs = SyncExercices(i, theme, exceptions)
|
errs = SyncExercices(i, theme, exceptions)
|
||||||
|
|
||||||
|
@ -107,6 +107,9 @@ func (i GitImporter) Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i GitImporter) Sync() error {
|
func (i GitImporter) Sync() error {
|
||||||
|
oneGitPull.Lock()
|
||||||
|
defer oneGitPull.Unlock()
|
||||||
|
|
||||||
r, err := git.PlainOpen(i.li.Base)
|
r, err := git.PlainOpen(i.li.Base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -5,10 +5,13 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gitRemoteRe = regexp.MustCompile(`^(?:(?:git@|https://)([\w.@]+)(?:/|:))((?:[\w-_]+)/(?:[\w-_/]+))(?:.git){0,1}(?:(?:/){0,1})$`)
|
var gitRemoteRe = regexp.MustCompile(`^(?:(?:git@|https://)([\w.@]+)(?:/|:))((?:[\w-_]+)/(?:[\w-_/]+))(?:.git){0,1}(?:(?:/){0,1})$`)
|
||||||
|
|
||||||
|
var oneGitPull sync.Mutex
|
||||||
|
|
||||||
func countFileInDir(dirname string) (int, error) {
|
func countFileInDir(dirname string) (int, error) {
|
||||||
files, err := os.ReadDir(dirname)
|
files, err := os.ReadDir(dirname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,6 +96,9 @@ func (i GitImporter) Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i GitImporter) Sync() error {
|
func (i GitImporter) Sync() error {
|
||||||
|
oneGitPull.Lock()
|
||||||
|
defer oneGitPull.Unlock()
|
||||||
|
|
||||||
log.Println("Synchronizing local git repository...")
|
log.Println("Synchronizing local git repository...")
|
||||||
cmdfetch := exec.Command("git", "-C", i.li.Base, "fetch", "origin")
|
cmdfetch := exec.Command("git", "-C", i.li.Base, "fetch", "origin")
|
||||||
stdout, err := cmdfetch.CombinedOutput()
|
stdout, err := cmdfetch.CombinedOutput()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user