Skip to content

Commit 2cabb19

Browse files
committed
function: make language cache size configurable
Signed-off-by: Miguel Molina <[email protected]>
1 parent 642c7d7 commit 2cabb19

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

docs/using-gitbase/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| `GITBASE_INDEX_DIR` | directory to save indexes, default `/var/lib/gitbase/index` |
1313
| `GITBASE_TRACE` | enable jaeger tracing, default disabled |
1414
| `GITBASE_READONLY` | allow read queries only, disabling creating and deleting indexes, default disabled |
15+
| `GITBASE_LANGUAGE_CACHE_SIZE` | size of the cache for the `language` UDF. The size is the maximum number of elements kept in the cache, 10000 by default |
1516

1617
### Jaeger tracing variables
1718

internal/function/language.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,34 @@ import (
44
"encoding/binary"
55
"fmt"
66
"hash/crc32"
7+
"os"
8+
"strconv"
79

810
lru "github.com/hashicorp/golang-lru"
911
enry "gopkg.in/src-d/enry.v1"
1012
"gopkg.in/src-d/go-mysql-server.v0/sql"
1113
)
1214

13-
const defaultLanguageCacheSize = 10000
15+
const (
16+
languageCacheSizeKey = "GITBASE_LANGUAGE_CACHE_SIZE"
17+
defaultLanguageCacheSize = 10000
18+
)
19+
20+
func languageCacheSize() int {
21+
v := os.Getenv(languageCacheSizeKey)
22+
size, err := strconv.Atoi(v)
23+
if err != nil || size <= 0 {
24+
size = defaultLanguageCacheSize
25+
}
26+
27+
return size
28+
}
1429

1530
var languageCache *lru.TwoQueueCache
1631

1732
func init() {
1833
var err error
19-
languageCache, err = lru.New2Q(defaultLanguageCacheSize)
34+
languageCache, err = lru.New2Q(languageCacheSize())
2035
if err != nil {
2136
panic(fmt.Errorf("cannot initialize language cache: %s", err))
2237
}

0 commit comments

Comments
 (0)