diff options
author | Luca Milanesio <luca.milanesio@gmail.com> | 2021-10-02 00:50:29 +0100 |
---|---|---|
committer | Fabio Ponciroli <ponch78@gmail.com> | 2024-03-25 22:56:11 +0000 |
commit | 3587102a0d960a36e44b60f4c97d7fb1db36d5f4 (patch) | |
tree | be358139222866a90f353224b42ced55e2571e9b | |
parent | db87562c4968541ecb09d21354cec13193046d60 (diff) |
Reuse the same Repository when listing changes by statusupstream/stable-2.16
Certain queries for multiple changes based on status
need to read the change meta-data from NoteDb on the same
repository. Do not re-open the same repository over and over
again but rather reuse the same in-memory Repository object
with consequent saving in CPU and lowering the systemload
during the execution of change queries.
The existing loading of multiple change notes without passing
the Repository object as parameter is kept for backward
compatibility and can be safely removed on master because
no more referenced by the Gerrit code-base.
Release-Notes: Reuse the same Repository when listing changes by status
Forward-Compatible: checked
Change-Id: I683a1b0cd4dcc64e191df6777dfce059745d5ce9
-rw-r--r-- | java/com/google/gerrit/server/notedb/ChangeNotes.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/java/com/google/gerrit/server/notedb/ChangeNotes.java b/java/com/google/gerrit/server/notedb/ChangeNotes.java index e2ddd87d0b..1ee446d789 100644 --- a/java/com/google/gerrit/server/notedb/ChangeNotes.java +++ b/java/com/google/gerrit/server/notedb/ChangeNotes.java @@ -72,6 +72,7 @@ import java.io.IOException; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -206,6 +207,12 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> { return new ChangeNotes(args, loadChangeFromDb(db, project, changeId)).load(); } + public ChangeNotes create( + ReviewDb db, Repository repo, Project.NameKey project, Change.Id changeId) + throws OrmException { + return new ChangeNotes(args, loadChangeFromDb(db, project, changeId), null).load(repo); + } + public ChangeNotes createWithAutoRebuildingDisabled( ReviewDb db, Project.NameKey project, Change.Id changeId) throws OrmException { return new ChangeNotes(args, loadChangeFromDb(db, project, changeId), true, false, null, null) @@ -265,6 +272,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> { public List<ChangeNotes> create( ReviewDb db, + Repository repo, Project.NameKey project, Collection<Change.Id> changeIds, Predicate<ChangeNotes> predicate) @@ -273,7 +281,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> { if (args.migration.readChanges()) { for (Change.Id cid : changeIds) { try { - ChangeNotes cn = create(db, project, cid); + ChangeNotes cn = create(db, repo, project, cid); if (cn.getChange() != null && predicate.test(cn)) { notes.add(cn); } @@ -297,6 +305,29 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> { return notes; } + /* TODO: This is now unused in the Gerrit code-base, however it is kept in the code + /* because it is a public method in a stable branch. + * It can be removed in master branch where we have more flexibility to change the API + * interface. + */ + public List<ChangeNotes> create( + ReviewDb db, + Project.NameKey project, + Collection<Change.Id> changeIds, + Predicate<ChangeNotes> predicate) { + try (Repository repo = args.repoManager.openRepository(project)) { + return create(db, repo, project, changeIds, predicate); + } catch (OrmException e) { + // The repository does not exist, hence it does not contain + // any change. + } catch (IOException e) { + logger.atWarning().withCause(e).log( + "Unable to open project=%s when trying to retrieve changeId=%s from NoteDb", + project, changeIds); + } + return Collections.emptyList(); + } + public ListMultimap<Project.NameKey, ChangeNotes> create( ReviewDb db, Predicate<ChangeNotes> predicate) throws IOException, OrmException { ListMultimap<Project.NameKey, ChangeNotes> m = |