Factor out approvals change status syncing
The changeOpen status is cached in the PatchSetApprovals table for performance reasons, so the approvals must be updated whenever the change status changes. This update is done in a few places and is likely not ever obvious why the update is being done. Make a function to do the update which makes the code self documenting all while sharing the implementation. Create an new ApprovalsUtil class for this function which can be a good place for more approval manipulating functions in the future. Change-Id: If92f3757963048a141003304f2c96036c915ab89
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (C) 2009 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.server;
|
||||||
|
|
||||||
|
import com.google.gerrit.reviewdb.Change;
|
||||||
|
import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||||
|
import com.google.gerrit.reviewdb.ReviewDb;
|
||||||
|
import com.google.gwtorm.client.OrmException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ApprovalsUtil {
|
||||||
|
/* Resync the changeOpen status which is cached in the approvals table for
|
||||||
|
performance reasons*/
|
||||||
|
public static void syncChangeStatus(final ReviewDb db, final Change change)
|
||||||
|
throws OrmException {
|
||||||
|
final List<PatchSetApproval> approvals =
|
||||||
|
db.patchSetApprovals().byChange(change.getId()).toList();
|
||||||
|
for (PatchSetApproval a : approvals) {
|
||||||
|
a.cache(change);
|
||||||
|
}
|
||||||
|
db.patchSetApprovals().update(approvals);
|
||||||
|
}
|
||||||
|
}
|
@@ -403,12 +403,7 @@ public class ChangeUtil {
|
|||||||
}
|
}
|
||||||
db.changeMessages().insert(Collections.singleton(cmsg));
|
db.changeMessages().insert(Collections.singleton(cmsg));
|
||||||
|
|
||||||
final List<PatchSetApproval> approvals =
|
ApprovalsUtil.syncChangeStatus(db, change);
|
||||||
db.patchSetApprovals().byChange(change.getId()).toList();
|
|
||||||
for (PatchSetApproval a : approvals) {
|
|
||||||
a.cache(change);
|
|
||||||
}
|
|
||||||
db.patchSetApprovals().update(approvals);
|
|
||||||
|
|
||||||
// Email the reviewers
|
// Email the reviewers
|
||||||
final ReplyToChangeSender cm = senderFactory.create(change);
|
final ReplyToChangeSender cm = senderFactory.create(change);
|
||||||
|
@@ -33,6 +33,7 @@ import com.google.gerrit.reviewdb.PatchSetInfo;
|
|||||||
import com.google.gerrit.reviewdb.Project;
|
import com.google.gerrit.reviewdb.Project;
|
||||||
import com.google.gerrit.reviewdb.RevId;
|
import com.google.gerrit.reviewdb.RevId;
|
||||||
import com.google.gerrit.reviewdb.ReviewDb;
|
import com.google.gerrit.reviewdb.ReviewDb;
|
||||||
|
import com.google.gerrit.server.ApprovalsUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
@@ -1830,12 +1831,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
|||||||
change.setStatus(Change.Status.MERGED);
|
change.setStatus(Change.Status.MERGED);
|
||||||
ChangeUtil.updated(change);
|
ChangeUtil.updated(change);
|
||||||
|
|
||||||
final List<PatchSetApproval> approvals =
|
ApprovalsUtil.syncChangeStatus(db, change);
|
||||||
db.patchSetApprovals().byChange(change.getId()).toList();
|
|
||||||
for (PatchSetApproval a : approvals) {
|
|
||||||
a.cache(change);
|
|
||||||
}
|
|
||||||
db.patchSetApprovals().update(approvals);
|
|
||||||
|
|
||||||
final StringBuilder msgBuf = new StringBuilder();
|
final StringBuilder msgBuf = new StringBuilder();
|
||||||
msgBuf.append("Change has been successfully pushed");
|
msgBuf.append("Change has been successfully pushed");
|
||||||
|
Reference in New Issue
Block a user