AccountPatchReviewStore: add possibility to cleanReviewed by change
It simplifies the clean up when change gets removed. Change-Id: I10387b85a80a0fb8d62f686cc8f33c146a856ff3 Signed-off-by: Jacek Centkowski <jcentkowski@collab.net>
This commit is contained in:
@@ -17,6 +17,7 @@ package com.google.gerrit.server.change;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
@@ -81,6 +82,13 @@ public interface AccountPatchReviewStore {
|
||||
*/
|
||||
void clearReviewed(PatchSet.Id psId);
|
||||
|
||||
/**
|
||||
* Clears the reviewed flags for all files in all patch sets in the given change for all users.
|
||||
*
|
||||
* @param changeId change ID
|
||||
*/
|
||||
void clearReviewed(Change.Id changeId);
|
||||
|
||||
/**
|
||||
* Find the latest patch set, that is smaller or equals to the given patch set, where at least,
|
||||
* one file has been reviewed by the given user.
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DeleteChangeOp implements BatchUpdateOp {
|
||||
ensureDeletable(ctx, id, patchSets);
|
||||
// Cleaning up is only possible as long as the change and its elements are
|
||||
// still part of the database.
|
||||
cleanUpReferences(ctx, id, patchSets);
|
||||
cleanUpReferences(ctx, id);
|
||||
|
||||
ctx.deleteChange();
|
||||
changeDeleted.fire(ctx.getChange(), ctx.getAccount(), ctx.getWhen());
|
||||
@@ -104,11 +104,8 @@ public class DeleteChangeOp implements BatchUpdateOp {
|
||||
return revWalk.isMergedInto(revWalk.parseCommit(objectId), revWalk.parseCommit(destId.get()));
|
||||
}
|
||||
|
||||
private void cleanUpReferences(ChangeContext ctx, Change.Id id, Collection<PatchSet> patchSets)
|
||||
throws NoSuchChangeException {
|
||||
for (PatchSet ps : patchSets) {
|
||||
accountPatchReviewStore.run(s -> s.clearReviewed(ps.getId()));
|
||||
}
|
||||
private void cleanUpReferences(ChangeContext ctx, Change.Id id) throws NoSuchChangeException {
|
||||
accountPatchReviewStore.run(s -> s.clearReviewed(id));
|
||||
|
||||
// Non-atomic operation on Accounts table; not much we can do to make it
|
||||
// atomic.
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.lifecycle.LifecycleModule;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.change.AccountPatchReviewStore;
|
||||
import com.google.gerrit.server.config.ConfigUtil;
|
||||
@@ -294,6 +295,18 @@ public abstract class JdbcAccountPatchReviewStore
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearReviewed(Change.Id changeId) {
|
||||
try (Connection con = ds.getConnection();
|
||||
PreparedStatement stmt =
|
||||
con.prepareStatement("DELETE FROM account_patch_reviews WHERE change_id = ?")) {
|
||||
stmt.setInt(1, changeId.get());
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw convertError("delete", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PatchSetWithReviewedFiles> findReviewed(PatchSet.Id psId, Account.Id accountId) {
|
||||
try (Connection con = ds.getConnection();
|
||||
|
||||
Reference in New Issue
Block a user