Lazily build ChangeControls from ChangeData
This simplifies logic in a few places where this is used. Change-Id: I1bd2c931ba5d03e05d50050fa964b4e3da14c23c
This commit is contained in:
@@ -86,6 +86,7 @@ import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
@@ -349,22 +350,20 @@ public class ChangeJson {
|
||||
}
|
||||
|
||||
private ChangeControl control(ChangeData cd) throws OrmException {
|
||||
ChangeControl ctrl = cd.changeControl();
|
||||
if (ctrl != null && ctrl.getCurrentUser() == userProvider.get()) {
|
||||
return ctrl;
|
||||
} else if (lastControl != null
|
||||
if (lastControl != null
|
||||
&& cd.getId().equals(lastControl.getChange().getId())) {
|
||||
return lastControl;
|
||||
}
|
||||
|
||||
ChangeControl ctrl;
|
||||
try {
|
||||
Change change = cd.change();
|
||||
if (change == null) {
|
||||
return null;
|
||||
if (cd.hasChangeControl()) {
|
||||
ctrl = cd.changeControl().forUser(userProvider.get());
|
||||
} else {
|
||||
ctrl = projectControls.get(cd.change().getProject())
|
||||
.controlFor(cd.change());
|
||||
}
|
||||
ctrl = projectControls.get(change.getProject()).controlFor(change);
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
} catch (NoSuchChangeException | ExecutionException e) {
|
||||
throw new OrmException(e);
|
||||
}
|
||||
lastControl = ctrl;
|
||||
return ctrl;
|
||||
|
||||
Reference in New Issue
Block a user