Batch more deletes together when deleting draft changes
Rather than looping over all patch sets and doing lookup/delete per patch set across several tables, just lookup/delete by change at the end of the loop. The AccountPatchReviews table does not have an index for this, so leave that one in the loop. Change-Id: I4676fda28c6635e67f717c84b66657d24cc285e1
This commit is contained in:
@@ -24,6 +24,7 @@ import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -66,6 +67,9 @@ public class DraftChangeIT extends AbstractDaemonTest {
|
||||
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
|
||||
RestResponse response = deleteChange(changeId, adminSession);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NO_CONTENT);
|
||||
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
get(triplet);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -370,11 +370,22 @@ public class ChangeUtil {
|
||||
db.changes().beginTransaction(change.getId());
|
||||
try {
|
||||
Map<RevId, String> refsToDelete = new HashMap<>();
|
||||
for (PatchSet ps : db.patchSets().byChange(changeId)) {
|
||||
// These should all be draft patch sets.
|
||||
deleteOnlyDraftPatchSetPreserveRef(db, ps);
|
||||
refsToDelete.put(ps.getRevision(), ps.getRefName());
|
||||
List<PatchSet> patchSets = db.patchSets().byChange(changeId).toList();
|
||||
for (PatchSet ps : patchSets) {
|
||||
if (!ps.isDraft()) {
|
||||
throw new NoSuchChangeException(changeId);
|
||||
}
|
||||
refsToDelete.put(ps.getRevision(), ps.getRefName());
|
||||
db.accountPatchReviews().delete(
|
||||
db.accountPatchReviews().byPatchSet(ps.getId()));
|
||||
}
|
||||
|
||||
// No need to delete from notedb; draft patch sets will be filtered out.
|
||||
db.patchComments().delete(db.patchComments().byChange(changeId));
|
||||
|
||||
db.patchSetApprovals().delete(db.patchSetApprovals().byChange(changeId));
|
||||
db.patchSetAncestors().delete(db.patchSetAncestors().byChange(changeId));
|
||||
db.patchSets().delete(patchSets);
|
||||
db.changeMessages().delete(db.changeMessages().byChange(changeId));
|
||||
db.starredChanges().delete(db.starredChanges().byChange(changeId));
|
||||
db.changes().delete(Collections.singleton(change));
|
||||
@@ -384,7 +395,8 @@ public class ChangeUtil {
|
||||
RevWalk rw = new RevWalk(repo)) {
|
||||
BatchRefUpdate ru = repo.getRefDatabase().newBatchUpdate();
|
||||
for (Map.Entry<RevId, String> e : refsToDelete.entrySet()) {
|
||||
ru.addCommand(new ReceiveCommand(ObjectId.fromString(e.getKey().get()),
|
||||
ru.addCommand(
|
||||
new ReceiveCommand(ObjectId.fromString(e.getKey().get()),
|
||||
ObjectId.zeroId(), e.getValue()));
|
||||
}
|
||||
ru.execute(rw, NullProgressMonitor.INSTANCE);
|
||||
|
||||
Reference in New Issue
Block a user