commit | 77e3bf80c45772132a7ae0697ffd1f82dd8dce32 | [log] [tgz] |
---|---|---|
author | Edwin Kempin <ekempin@google.com> | Thu Feb 25 17:01:34 2021 +0100 |
committer | Edwin Kempin <ekempin@google.com> | Fri Feb 26 11:23:23 2021 +0100 |
tree | 5bcaa6b812015a1e2f322c44d160d20d9737430a | |
parent | 097eab3a19b399ec44b0f882b4ae18c9ebf372ff [diff] |
Load each code owner config only once for computing code owner statuses When computing code owner statuses we need to iterate over the relevant code owner configs for each of the files that have been touched in the change. In this process code owner config files that apply to multiple files are loaded multiple times (e.g. the root code owner config is loaded once per file). To reduce the number of code owner config loads we add a transient in-memory cache that caches the loaded code owner config files for the time of the code owner computation. Once the computation is done the cache is dropped. The implementation of the cache is rather simple. It has a HashMap in which it stores loaded code owner configs. If a requested code owner config is available in the map it is returned, otherwise the code owner config is loaded and put into the cache. The implementation of the cache is not thread-safe, but since we create a new instance for every request and the request processes file synchronously it also doesn't need to be thread-safe. The cache is instantiated in CodeOwnerConfigHierarchy which loads the code owner config files that are relevant for a path. Previously CodeOwnerConfigHierarchy was a singleton, but now the @Singleton annotation was removed so that each instance gets its own cache. The cache is passed over into PathCodeOwners which does the actual loading of code owner configs. CodeOwnerApprovalCache takes care to instantiate CodeOwnerConfigHierarchy outside the loop that iterates over all files, so that the same instance, and hence the same cache, is used for all files. Other classes that get CodeOwnerConfigHierarchy injected (CheckCodeOwner, AbstractGetCodeOwnersForPath) are non-sigleton and hence don't need to be adapted. PathCodeOwners also has other callers that do not require caching. Hence PathCodeOwners can be used, with or without cache. To support this we add a new CodeOwnerConfigLoader interface that is implemented by CodeOwners (loads code owner configs from the backend) and the new cache (retrieves code owner configs from the cache, or falls back to CodeOwners). There are no unit tests for the new cache class yet, but the test coverage shows that it is fully covered by the existing tests (except the catch block for exception handling). This change also adds a new metric for counting the number of code owner configs that have been returned from cache. This way we will be able to see what difference this change made. Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: Id72def08ee26b2f7457a4e83e42ee46e7cbec0dc
This plugin provides support for defining code owners for files in a repository.
If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.
Also see resources/Documentation/about.md.
IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md.