hugolib: Avoid processing the same notify event twice
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 12 Apr 2017 08:07:08 +0000 (10:07 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 12 Apr 2017 19:15:51 +0000 (21:15 +0200)
On `macOS`, at least, we've seen multiple WRITE events for same file, and no need to do the same job twice.

hugolib/site.go

index 768fe147f9fe5d4983d40d448b44d57ff7d7ff98..d8e40f039f037f5401adb6acd6d92c0d5af5c90b 100644 (file)
@@ -633,8 +633,15 @@ func (s *Site) reProcess(events []fsnotify.Event) (whatChanged, error) {
        shortcodesChanged := make(map[string]bool)
        // prevent spamming the log on changes
        logger := helpers.NewDistinctFeedbackLogger()
+       seen := make(map[fsnotify.Event]bool)
 
        for _, ev := range events {
+               // Avoid processing the same event twice.
+               if seen[ev] {
+                       continue
+               }
+               seen[ev] = true
+
                if s.isContentDirEvent(ev) {
                        logger.Println("Source changed", ev.Name)
                        sourceChanged = append(sourceChanged, ev)