From 42513df8b8c75e3babca445dc8bc1fbb69367c7e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 6 Nov 2013 13:31:30 -0500 Subject: [PATCH] godoc: add IndexInterval option This will permit deleting some forked code elsewhere. R=golang-dev, crawshaw CC=golang-dev https://golang.org/cl/22010046 --- godoc/corpus.go | 6 ++++++ godoc/index.go | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/godoc/corpus.go b/godoc/corpus.go index ed26894707..d8d19e57bd 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 da97ce0a57..34c4c35205 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) }