diff --git a/godoc/corpus.go b/godoc/corpus.go index ed268947..d8d19e57 100644 --- a/godoc/corpus.go +++ b/godoc/corpus.go @@ -39,6 +39,12 @@ type Corpus struct { // zero value for IndexThrottle means 0.9. IndexThrottle float64 + // IndexInterval specifies the time to sleep between reindexing + // all the sources. + // If zero, a default is used. If negative, the index is only + // built once. + IndexInterval time.Duration + // MaxResults optionally specifies the maximum results for indexing. // The default is 1000. MaxResults int diff --git a/godoc/index.go b/godoc/index.go index da97ce0a..34c4c352 100644 --- a/godoc/index.go +++ b/godoc/index.go @@ -1167,7 +1167,8 @@ func (c *Corpus) RunIndexer() { // initialize the index from disk if possible if c.IndexFiles != "" { if err := c.readIndex(c.IndexFiles); err != nil { - log.Printf("error reading index: %s", err) + log.Printf("error reading index from file %s: %v", c.IndexFiles, err) + return } } @@ -1177,10 +1178,12 @@ func (c *Corpus) RunIndexer() { // index possibly out of date - make a new one c.UpdateIndex() } - delay := 60 * time.Second // by default, try every 60s - if false { // TODO(bradfitz): was: *testDir != "" { - // in test mode, try once a second for fast startup - delay = 1 * time.Second + if c.IndexInterval < 0 { + return + } + delay := 5 * time.Minute // by default, reindex every 5 minutes + if c.IndexInterval > 0 { + delay = c.IndexInterval } time.Sleep(delay) }