Remove TM references from GaeUserIdConverter (#1666)

This is the only user of the ofy code that will stick around at least
until we move to the new registrar console. By removing references to
the transaction manager, we will be able to delete all the tm code
without interfering with this.
This commit is contained in:
gbrodman 2022-06-13 11:47:39 -04:00 committed by GitHub
parent 6ff4aaeb1c
commit dcc11379c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 18 deletions

View file

@ -16,7 +16,7 @@ package google.registry.model.common;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.IdService.allocateId;
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
import com.google.appengine.api.users.User;
import com.google.common.base.Splitter;
@ -55,22 +55,19 @@ public class GaeUserIdConverter extends ImmutableObject {
try {
// Perform these operations in a transactionless context to avoid enlisting in some outer
// transaction (if any).
ofyTm()
auditedOfy()
.doTransactionless(
() -> {
ofyTm().putWithoutBackup(gaeUserIdConverter);
auditedOfy().saveWithoutBackup().entity(gaeUserIdConverter).now();
return null;
});
// The read must be done in its own transaction to avoid reading from the session cache.
return ofyTm().transactNew(() -> ofyTm().loadByEntity(gaeUserIdConverter).user.getUserId());
return auditedOfy()
.transactNew(() -> auditedOfy().load().entity(gaeUserIdConverter).now().user.getUserId());
} finally {
ofyTm()
auditedOfy()
.doTransactionless(
() -> {
ofyTm().deleteWithoutBackup(gaeUserIdConverter);
return null;
});
() -> auditedOfy().deleteWithoutBackup().entity(gaeUserIdConverter).now());
}
}
}

View file

@ -242,7 +242,7 @@ public class Ofy {
}
/** Pause the current transaction (if any) and complete this one before returning to it. */
<R> R transactNew(Supplier<R> work) {
public <R> R transactNew(Supplier<R> work) {
// Wrap the Work in a CommitLoggedWork so that we can give transactions a frozen view of time
// and maintain commit logs for them.
return transactCommitLoggedWork(new CommitLoggedWork<>(work, getClock()));

View file

@ -15,8 +15,7 @@
package google.registry.model.common;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
import google.registry.testing.AppEngineExtension;
import org.junit.jupiter.api.AfterEach;
@ -32,7 +31,7 @@ public class GaeUserIdConverterTest {
@AfterEach
void verifyNoLingeringEntities() {
assertThat(ofyTm().loadAllOf(GaeUserIdConverter.class)).hasSize(0);
assertThat(auditedOfy().load().type(GaeUserIdConverter.class).count()).isEqualTo(0);
}
@Test
@ -43,9 +42,12 @@ public class GaeUserIdConverterTest {
@Test
void testSuccess_inTransaction() {
tm().transactNew(
() ->
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
.matches("[0-9]+"));
auditedOfy()
.transactNew(
() -> {
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
.matches("[0-9]+");
return null;
});
}
}