Filter in SQL when updating/deleting alloc tokens (#2244)

This doesn't fix any issues with dead/livelocks when deleting or
updating allocation tokens, but it at least will significantly reduce
the time to load the tokens that we'll want to update/delete.
This commit is contained in:
gbrodman 2023-12-04 19:24:17 -05:00 committed by GitHub
parent dd86c56ddc
commit cc9b3f5965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,9 +67,12 @@ abstract class UpdateOrDeleteAllocationTokensCommand extends ConfirmingCommand {
checkArgument(!prefix.isEmpty(), "Provided prefix should not be blank"); checkArgument(!prefix.isEmpty(), "Provided prefix should not be blank");
return tm().transact( return tm().transact(
() -> () ->
tm().loadAllOf(AllocationToken.class).stream() tm().query(
.filter(token -> token.getToken().startsWith(prefix)) "SELECT token FROM AllocationToken WHERE token LIKE :prefix",
.map(AllocationToken::createVKey) String.class)
.setParameter("prefix", String.format("%s%%", prefix))
.getResultStream()
.map(token -> VKey.create(AllocationToken.class, token))
.collect(toImmutableList())); .collect(toImmutableList()));
} }
} }