[gerrit_utils] Add caching to ShouldUseSSO

This only lasts per process invocation, so we don't worry about cache
size (and it's a minor performance save).

Bug: b/350806563
Change-Id: Ie8e1aa2933c5582a3a2e2f75f04590f6bb432c4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5833280
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
changes/80/5833280/2
Allen Li 8 months ago committed by LUCI CQ
parent dc8d502d13
commit 3a7d070966

@ -11,6 +11,7 @@ from __future__ import annotations
import base64
import contextlib
import functools
import http.cookiejar
import json
import logging
@ -173,6 +174,7 @@ class SSOHelper(object):
ssoHelper = SSOHelper()
@functools.lru_cache(maxsize=None)
def ShouldUseSSO(host: str, email: str) -> bool:
"""Return True if we should use SSO for the given Gerrit host and user."""
LOGGER.debug("Determining whether we should use SSO...")

@ -731,17 +731,15 @@ class ShouldUseSSOTest(unittest.TestCase):
def setUp(self) -> None:
self.newauth = mock.patch('newauth.Enabled', return_value=True)
self.newauth.start()
self.cwd = mock.patch('os.getcwd', return_value='/fake/cwd')
self.cwd.start()
self.sso = mock.patch('gerrit_util.ssoHelper.find_cmd',
return_value='/fake/git-remote-sso')
self.sso.start()
scm_mock.GIT(self)
self.addCleanup(mock.patch.stopall)
gerrit_util.ShouldUseSSO.cache_clear()
return super().setUp()
def tearDown(self) -> None:

Loading…
Cancel
Save