summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaushik Lingarkar <kaushik.lingarkar@linaro.org>2022-06-06 12:19:57 -0700
committerKaushik Lingarkar <kaushik.lingarkar@linaro.org>2022-06-06 12:43:04 -0700
commit531bcff6479c2c635e0e32eaddfb41c1e98315e4 (patch)
tree14ed1efbe15f939b931038bd7b6f23450976a179
parent598b676a96d5c6b61ae6b85748311ec4677cac62 (diff)
Avoid creating an IdentifiedUser multiple times in a SSH query
In SSH scope, we are creating an IdentifiedUser each time we try to get the user. In I141e9bf2, it seems that the intention was to create the identified user only the first time it was asked for. Creating a new IdentifiedUser each time adds an overhead that degrades query performance. We do want the IdentifiedUser created via the RequestFactory so that request scoped fields are populated correctly which is why we don't directly return CurrentUser#asIdentifiedUser(). Release-Notes: SSH query performance is improved Change-Id: Ibca6c2320ed3abd7bfa6bf29daaacb5048d6a798
-rw-r--r--java/com/google/gerrit/sshd/SshScope.java8
1 files changed, 6 insertions, 2 deletions
diff --git a/java/com/google/gerrit/sshd/SshScope.java b/java/com/google/gerrit/sshd/SshScope.java
index 340b910c59..59f3f0cc13 100644
--- a/java/com/google/gerrit/sshd/SshScope.java
+++ b/java/com/google/gerrit/sshd/SshScope.java
@@ -43,6 +43,8 @@ public class SshScope {
volatile long started;
volatile long finished;
+ private IdentifiedUser identifiedUser;
+
private Context(SshSession s, String c, long at) {
session = s;
commandLine = c;
@@ -68,8 +70,10 @@ public class SshScope {
public CurrentUser getUser() {
CurrentUser user = session.getUser();
if (user != null && user.isIdentifiedUser()) {
- IdentifiedUser identifiedUser = userFactory.create(user.getAccountId());
- identifiedUser.setAccessPath(user.getAccessPath());
+ if (identifiedUser == null) {
+ identifiedUser = userFactory.create(user.getAccountId());
+ identifiedUser.setAccessPath(user.getAccessPath());
+ }
return identifiedUser;
}
return user;