backend: new option --skipInitialGeneration to skip the full static files regeneratio...
authorPierre-Olivier Mercier <nemunaire@nemunai.re>
Sun, 9 Dec 2018 18:46:18 +0000 (19:46 +0100)
committerPierre-Olivier Mercier <nemunaire@nemunai.re>
Sun, 9 Dec 2018 23:31:29 +0000 (00:31 +0100)
backend/main.go

index 2b7e9ee..96c8b60 100644 (file)
@@ -44,22 +44,27 @@ func watchsubdir(watcher *fsnotify.Watcher, pathname string) error {
 }
 
 var lastRegeneration time.Time
+var skipInitialGeneration = false
 
 func reloadSettings(config settings.FICSettings) {
        if lastRegeneration != config.Generation || fic.PartialValidation != config.PartialValidation || fic.UnlockedChallenges != !config.EnableExerciceDepend || fic.FirstBlood != config.FirstBlood || fic.SubmissionCostBase != config.SubmissionCostBase {
-               lastRegeneration = config.Generation
-
                fic.PartialValidation = config.PartialValidation
                fic.UnlockedChallenges = !config.EnableExerciceDepend
 
                fic.FirstBlood = config.FirstBlood
                fic.SubmissionCostBase = config.SubmissionCostBase
 
-               log.Println("Generating files...")
-               go func() {
-                       genAll()
-                       log.Println("Full generation done")
-               }()
+               if !skipInitialGeneration {
+                       log.Println("Generating files...")
+                       go func() {
+                               genAll()
+                               log.Println("Full generation done")
+                       }()
+               } else {
+                       skipInitialGeneration = false
+                       log.Println("Regeneration skipped by option.")
+               }
+               lastRegeneration = config.Generation
        } else {
                log.Println("No change found. Skipping regeneration.")
        }
@@ -72,6 +77,7 @@ func main() {
        flag.StringVar(&TeamsDir, "teams", "./TEAMS", "Base directory where save teams JSON files")
        flag.StringVar(&fic.FilesDir, "files", "/files", "Request path prefix to reach files")
        var debugINotify = flag.Bool("debuginotify", false, "Show skipped inotofy events")
+       flag.BoolVar(&skipInitialGeneration, "skipfullgeneration", skipInitialGeneration, "Skip the initial regeneration")
        flag.Parse()
 
        log.SetPrefix("[backend] ")