1
0
mirror of https://github.com/google/nomulus synced 2025-12-23 14:25:44 +00:00

Remove duplicate transaction in updateAllocTokens (#2637)

This commit is contained in:
gbrodman
2025-01-13 14:12:06 -05:00
committed by GitHub
parent cea3da01a0
commit 693467a165
2 changed files with 7 additions and 12 deletions

View File

@@ -52,7 +52,7 @@ final class DeleteAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
@Override @Override
public void init() { public void init() {
tokensToDelete = getTokenKeys(tokens, prefix); tokensToDelete = tm().transact(() -> getTokenKeys(tokens, prefix));
} }
@Override @Override

View File

@@ -59,21 +59,16 @@ abstract class UpdateOrDeleteAllocationTokensCommand extends ConfirmingCommand {
.map(token -> VKey.create(AllocationToken.class, token)) .map(token -> VKey.create(AllocationToken.class, token))
.collect(toImmutableList()); .collect(toImmutableList());
ImmutableList<VKey<AllocationToken>> nonexistentKeys = ImmutableList<VKey<AllocationToken>> nonexistentKeys =
tm().transact( keys.stream().filter(key -> !tm().exists(key)).collect(toImmutableList());
() -> keys.stream().filter(key -> !tm().exists(key)).collect(toImmutableList()));
checkState(nonexistentKeys.isEmpty(), "Tokens with keys %s did not exist", nonexistentKeys); checkState(nonexistentKeys.isEmpty(), "Tokens with keys %s did not exist", nonexistentKeys);
return keys; return keys;
} else { } else {
checkArgument(!prefix.isEmpty(), "Provided prefix should not be blank"); checkArgument(!prefix.isEmpty(), "Provided prefix should not be blank");
return tm().transact( return tm().query("SELECT token FROM AllocationToken WHERE token LIKE :prefix", String.class)
() -> .setParameter("prefix", String.format("%s%%", prefix))
tm().query( .getResultStream()
"SELECT token FROM AllocationToken WHERE token LIKE :prefix", .map(token -> VKey.create(AllocationToken.class, token))
String.class) .collect(toImmutableList());
.setParameter("prefix", String.format("%s%%", prefix))
.getResultStream()
.map(token -> VKey.create(AllocationToken.class, token))
.collect(toImmutableList()));
} }
} }
} }