admin: add a progression indicator for the deep synchronization
This commit is contained in:
parent
d9fb261232
commit
7227c7109e
4 changed files with 43 additions and 3 deletions
|
@ -18,10 +18,14 @@ var DeepReportPath = "full_import_report.json"
|
|||
// oneDeepSync ensure there is no more than one running deep sync.
|
||||
var oneDeepSync sync.Mutex
|
||||
|
||||
// DeepSyncProgress expose the progression of the depp synchronization (0 = 0%, 255 = 100%).
|
||||
var DeepSyncProgress uint8
|
||||
|
||||
// SyncDeep performs a recursive synchronisation: from themes to challenge items.
|
||||
func SyncDeep(i Importer) (errs map[string][]string) {
|
||||
oneDeepSync.Lock()
|
||||
defer oneDeepSync.Unlock()
|
||||
DeepSyncProgress = 1
|
||||
|
||||
errs = map[string][]string{}
|
||||
|
||||
|
@ -29,19 +33,28 @@ func SyncDeep(i Importer) (errs map[string][]string) {
|
|||
errs["_themes"] = SyncThemes(i)
|
||||
|
||||
if themes, err := fic.GetThemes(); err == nil {
|
||||
for _, theme := range themes {
|
||||
DeepSyncProgress = 2
|
||||
var themeStep uint8 = uint8(250) / uint8(len(themes))
|
||||
|
||||
for tid, theme := range themes {
|
||||
DeepSyncProgress = 3 + uint8(tid) * themeStep
|
||||
errs[theme.Name] = SyncExercices(i, theme)
|
||||
|
||||
if exercices, err := theme.GetExercices(); err == nil {
|
||||
for _, exercice := range exercices {
|
||||
var exerciceStep uint8 = themeStep / uint8(len(exercices))
|
||||
for eid, exercice := range exercices {
|
||||
DeepSyncProgress = 3 + uint8(tid) * themeStep + uint8(eid) * exerciceStep
|
||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
|
||||
DeepSyncProgress += exerciceStep / 3
|
||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFlags(i, exercice)...)
|
||||
DeepSyncProgress += exerciceStep / 3
|
||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceHints(i, exercice)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeepSyncProgress = 254
|
||||
errs["_date"] = append(errs["_date"], fmt.Sprintf("%v", time.Now()))
|
||||
|
||||
errs["_regeneration"] = []string{}
|
||||
|
@ -66,5 +79,6 @@ func SyncDeep(i Importer) (errs map[string][]string) {
|
|||
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
|
||||
}
|
||||
|
||||
DeepSyncProgress = 255
|
||||
return
|
||||
}
|
||||
|
|
Reference in a new issue