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:
Jacek Centkowski
2019-05-14 12:35:10 +02:00
parent f7b51c3f2c
commit 3dd45c93ff
3 changed files with 24 additions and 6 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.change;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.gerrit.reviewdb.client.Account; 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.reviewdb.client.PatchSet;
import java.util.Collection; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
@@ -81,6 +82,13 @@ public interface AccountPatchReviewStore {
*/ */
void clearReviewed(PatchSet.Id psId); 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, * 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. * one file has been reviewed by the given user.

View File

@@ -71,7 +71,7 @@ public class DeleteChangeOp implements BatchUpdateOp {
ensureDeletable(ctx, id, patchSets); ensureDeletable(ctx, id, patchSets);
// Cleaning up is only possible as long as the change and its elements are // Cleaning up is only possible as long as the change and its elements are
// still part of the database. // still part of the database.
cleanUpReferences(ctx, id, patchSets); cleanUpReferences(ctx, id);
ctx.deleteChange(); ctx.deleteChange();
changeDeleted.fire(ctx.getChange(), ctx.getAccount(), ctx.getWhen()); 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())); return revWalk.isMergedInto(revWalk.parseCommit(objectId), revWalk.parseCommit(destId.get()));
} }
private void cleanUpReferences(ChangeContext ctx, Change.Id id, Collection<PatchSet> patchSets) private void cleanUpReferences(ChangeContext ctx, Change.Id id) throws NoSuchChangeException {
throws NoSuchChangeException { accountPatchReviewStore.run(s -> s.clearReviewed(id));
for (PatchSet ps : patchSets) {
accountPatchReviewStore.run(s -> s.clearReviewed(ps.getId()));
}
// Non-atomic operation on Accounts table; not much we can do to make it // Non-atomic operation on Accounts table; not much we can do to make it
// atomic. // atomic.

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.lifecycle.LifecycleModule; import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.reviewdb.client.Account; 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.reviewdb.client.PatchSet;
import com.google.gerrit.server.change.AccountPatchReviewStore; import com.google.gerrit.server.change.AccountPatchReviewStore;
import com.google.gerrit.server.config.ConfigUtil; 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 @Override
public Optional<PatchSetWithReviewedFiles> findReviewed(PatchSet.Id psId, Account.Id accountId) { public Optional<PatchSetWithReviewedFiles> findReviewed(PatchSet.Id psId, Account.Id accountId) {
try (Connection con = ds.getConnection(); try (Connection con = ds.getConnection();