From 61de9881daf32117a85e07377969e338d5d3d50c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 20 Apr 2018 19:40:11 -0700 Subject: [PATCH] pkg/index: redo indexing of a blob when CAMLI_REDO_INDEX_ON_RECEIVE is set So an upcoming HEIC reindexing tool. Updates #969 Change-Id: If194904d770bb670fa581c4e5e09c303806bc784 --- doc/environment-vars.md | 6 ++++++ pkg/index/receive.go | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/environment-vars.md b/doc/environment-vars.md index ead148a41..ccc0bb577 100644 --- a/doc/environment-vars.md +++ b/doc/environment-vars.md @@ -222,6 +222,12 @@ files to be ignored by [pkg/client](/pkg/client) when uploading. : If true, no thumbnail caching is done, and URLs even have cache buster components, to force browsers to reload a lot. +`CAMLI_REDO_INDEX_ON_RECEIVE` (bool) +: If true, the indexer will always index any blob it receives, regardless of + whether it thinks it's done it in the past. This is generally only useful when + working on the indexing code and retroactively indexing a subset of content + without forcing a global reindexing. + `CAMLI_VAR_DIR` (string) : Path used by [pkg/osutil](/pkg/osutil) to override operating system specific application storage directory. Generally unused. diff --git a/pkg/index/receive.go b/pkg/index/receive.go index d73e39365..e982352df 100644 --- a/pkg/index/receive.go +++ b/pkg/index/receive.go @@ -220,9 +220,17 @@ func (ix *Index) ReceiveBlob(ctx context.Context, blobRef blob.Ref, source io.Re } }() - if haveVal, haveErr := ix.s.Get("have:" + blobRef.String()); haveErr == nil { - if strings.HasSuffix(haveVal, "|indexed") { - return sbr, nil + // By default, return immediately if it looks like we already + // have indexed this blob before. But if the user has + // CAMLI_REDO_INDEX_ON_RECEIVE set in their environment, + // always index it. This is generally only useful when working + // on the indexing code and retroactively indexing a subset of + // content without forcing a global reindexing. + if allowReindex, _ := strconv.ParseBool(os.Getenv("CAMLI_REDO_INDEX_ON_RECEIVE")); !allowReindex { + if haveVal, haveErr := ix.s.Get("have:" + blobRef.String()); haveErr == nil { + if strings.HasSuffix(haveVal, "|indexed") { + return sbr, nil + } } }