mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Speed up presubmit by caching code-owners check
Currently, presubmit queries the gerrit server every run to check if the code-owners plugin is enabled. This CL caches that result in a /tmp file per repository. This saves as much as 1.5s per `git cl presubmit`. Change-Id: I1a3631074d1bcbb1a254caa6654fd8434f069aa2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7227749 Commit-Queue: Josiah Kiehl <kiehl@google.com> Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import os
|
||||
import random
|
||||
|
||||
import gerrit_util
|
||||
from gerrit_cache import GerritCache
|
||||
import git_common
|
||||
|
||||
|
||||
@@ -213,12 +214,22 @@ class GerritClient(OwnersClient):
|
||||
paths))
|
||||
|
||||
|
||||
def GetCodeOwnersClient(host, project, branch):
|
||||
def GetCodeOwnersClient(host, project, branch, cache=None):
|
||||
"""Get a new OwnersClient.
|
||||
|
||||
Uses GerritClient and raises an exception if code-owners plugin is not
|
||||
available."""
|
||||
if gerrit_util.IsCodeOwnersEnabledOnHost(host):
|
||||
key = GerritCache.get_host_code_owners_enabled_key(host)
|
||||
is_enabled = None
|
||||
if cache:
|
||||
is_enabled = cache.getBoolean(key)
|
||||
|
||||
if is_enabled is None:
|
||||
is_enabled = gerrit_util.IsCodeOwnersEnabledOnHost(host)
|
||||
if cache:
|
||||
cache.setBoolean(key, is_enabled)
|
||||
|
||||
if is_enabled:
|
||||
return GerritClient(host, project, branch)
|
||||
raise Exception(
|
||||
'code-owners plugin is not enabled. Ask your host admin to enable it '
|
||||
|
||||
Reference in New Issue
Block a user