Mark ApprovalCopier, ApprovalsUtil and LabelNormalizer as singleton

These have no per-request state and are held by several REST API views
that are themselves singletons.  Instead of making one copy per REST
view, make these singletons for the server.

Change-Id: I2f343d29c4bed8a862b3794323916ca46b8b1f99
This commit is contained in:
Shawn Pearce
2014-05-28 18:07:32 -07:00
parent afc949a5d3
commit d1624692bf
3 changed files with 6 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@@ -56,6 +57,7 @@ import java.util.TreeMap;
* database at submit time, or refreshed on demand, as when reading approvals
* from the notedb.
*/
@Singleton
public class ApprovalCopier {
private final GitRepositoryManager repoManager;
private final ProjectCache projectCache;

View File

@@ -49,6 +49,7 @@ import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.util.TimeUtil;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.sql.Timestamp;
import java.util.ArrayList;
@@ -70,6 +71,7 @@ import java.util.Set;
* <p>
* The methods in this class only modify the gwtorm database.
*/
@Singleton
public class ApprovalsUtil {
private static Ordering<PatchSetApproval> SORT_APPROVALS = Ordering.natural()
.onResultOf(new Function<PatchSetApproval, Timestamp>() {

View File

@@ -33,6 +33,7 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Collection;
import java.util.List;
@@ -46,6 +47,7 @@ import java.util.List;
* is originally made and a later point, for example when a change is submitted.
* This class normalizes old votes against current project configuration.
*/
@Singleton
public class LabelNormalizer {
public static class Result {
private final ImmutableList<PatchSetApproval> unchanged;