Remove unnecessary call to deleteAllSearchParams (#5901)

* Remove unnecessary call to deleteAllSearchParams. Fixes #5900.

* Regression test

* Run spotless
This commit is contained in:
holly-smile 2024-05-03 01:15:43 -07:00 committed by GitHub
parent 22d7731d41
commit b555498c9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 65 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 5900
jira: SMILE-7435
title: "Remove unnecessary call to deleteAllSearchParams when $expunge is called on an already-deleted resource."

View File

@ -298,7 +298,7 @@ public class JpaResourceExpungeService implements IResourceExpungeService<JpaPid
}
}
private void expungeCurrentVersionOfResource(
protected void expungeCurrentVersionOfResource(
RequestDetails theRequestDetails, Long theResourceId, AtomicInteger theRemainingCount) {
ResourceTable resource = myResourceTableDao.findById(theResourceId).orElseThrow(IllegalStateException::new);
@ -311,8 +311,6 @@ public class JpaResourceExpungeService implements IResourceExpungeService<JpaPid
ourLog.info(
"Expunging current version of resource {}", resource.getIdDt().getValue());
deleteAllSearchParams(JpaPid.fromId(resource.getResourceId()));
try {
if (resource.isHasTags()) {
myResourceTagDao.deleteByResourceId(resource.getId());

View File

@ -0,0 +1,59 @@
package ca.uhn.fhir.jpa.dao.expunge;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.dao.data.IResourceHistoryTableDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ch.qos.logback.classic.Logger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.LoggerFactory;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class JpaResourceExpungeServiceTest {
private static final Logger ourLog = (Logger) LoggerFactory.getLogger(JpaResourceExpungeService.class);
@InjectMocks
@Spy
private JpaResourceExpungeService myService = spy(new JpaResourceExpungeService());
@Mock
private IResourceTableDao myResourceTableDao;
@Mock
private IResourceHistoryTableDao myResourceHistoryTableDao;
@Mock
private RequestDetails myRequestDetails;
@Mock
private ResourceTable resourceTable;
@Mock
private JpaStorageSettings myStorageSettings;
@Test
public void testExpungeDoesNotDeleteAllSearchParams() {
when(myResourceTableDao.findById(any())).thenReturn(Optional.of(resourceTable));
when(resourceTable.getIdDt()).thenReturn(new IdDt());
myService.expungeCurrentVersionOfResource(myRequestDetails, 1L, new AtomicInteger(1));
verify(myService, never()).deleteAllSearchParams(any());
}
}