src-d / gitbase

SQL interface to git repositories, written in Go. https://docs.sourced.tech/gitbase
Apache License 2.0
2.07k stars 123 forks source link

gitbase: use only one cache for all repositories #898

Closed jfontan closed 5 years ago

jfontan commented 5 years ago

Also fix a bug getting the cache size from cli.

Before integrating the use of go-borges repositories were managed by RepositoryPool. When it was created it initialized a git object cache that is used by all the repositories. This cache is also used when using indexes and reading directly from packfiles (cache is retrieved with Repository.Cache(), https://github.com/src-d/gitbase/blob/master/packfiles.go#L239).

Now go-borges takes care of repository libraries and retrieving go-git repositories from them. To make it work the same we initialize go-borges library with a cache generated in gitbase (command.Server) but I forgot that RepositoryPool was also generating a cache internally and returning it when calling Repository.Cache(). This means that there was two different objects caches, one for repositories opened without indexes and other for reading packfiles when the index was used. The problems are:

The change makes RepositoryPool get an initialized cache that will be used by all repos (both with and without index).

juanjux commented 5 years ago

One question (not doubting, just want to understand better): what's the rationale for this change?

jfontan commented 5 years ago

One question (not doubting, just want to understand better): what's the rationale for this change?

@juanjux You are right, there was almost no description to the PR :see_no_evil:. I've updated the description with the problem it's fixing.

juanjux commented 5 years ago

@jfontan awesome description, thanks!

jfontan commented 5 years ago

I've just rebased with latest master.