Commit 3aa5a897 authored by Matija Obreza's avatar Matija Obreza
Browse files

Fix: getAccessions by UUIDs sublist bug

parent 35320b92
......@@ -137,8 +137,8 @@ public class AccessionServiceImpl implements AccessionService {
List<UUID> uuidList = new ArrayList<>(uuids);
List<Accession> accessions = new ArrayList<>(uuidList.size());
for (int i = 0; i < uuidList.size(); i+= chunkSize){
List<UUID> chunk = uuidList.subList(i, i+chunkSize);
for (int i = 0; i < uuids.size(); i+= chunkSize){
List<UUID> chunk = uuidList.subList(i, Math.min(uuids.size(), i+chunkSize));
accessions.addAll((List<Accession>) accessionRepository.findAll(QAccession.accession.accessionId.uuid.in(chunk)));
}
......
......@@ -17,7 +17,9 @@ package org.genesys2.server.service.worker;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.time.StopWatch;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
......@@ -58,6 +60,7 @@ public class AccessionRefAspect {
@Before(value = "execution(* org.genesys2.server.persistence.AccessionRepository.delete(*)) && args(arg)")
public void beforeDeleteAccession(JoinPoint joinPoint, Object arg) throws Throwable {
StopWatch stopWatch=StopWatch.createStarted();
LOG.trace("Before delete accession" + arg);
if (arg == null) {
return;
......@@ -67,9 +70,11 @@ public class AccessionRefAspect {
datasetsDereference((Accession) accession);
subsetsDereference((Accession) accession);
});
LOG.warn("Dereferencing AccessionRefs for {} accession took {}ms", ((Collection<?>) arg).size(), stopWatch.getTime(TimeUnit.MILLISECONDS));
} else if (arg instanceof Accession) {
datasetsDereference((Accession) arg);
subsetsDereference((Accession) arg);
LOG.warn("Dereferencing AccessionRefs for 1 accession took {}ms", stopWatch.getTime(TimeUnit.MILLISECONDS));
}
}
......@@ -97,14 +102,18 @@ public class AccessionRefAspect {
if (returnObject == null) {
return;
}
StopWatch stopWatch=StopWatch.createStarted();
if (returnObject instanceof Collection<?>) {
((Collection<?>) returnObject).forEach(accession -> {
updateDatasets((Accession) accession);
updateSubsets((Accession) accession);
});
LOG.warn("Re-referencing AccessionRefs for {} accessions took {}ms", ((Collection<?>) returnObject).size(), stopWatch.getTime(TimeUnit.MILLISECONDS));
} else if (returnObject instanceof Accession) {
updateDatasets((Accession) returnObject);
updateSubsets((Accession) returnObject);
LOG.warn("Re-referencing AccessionRefs for 1 accession took {}ms", stopWatch.getTime(TimeUnit.MILLISECONDS));
}
}
......
......@@ -156,21 +156,25 @@ public class AccessionControllerTest extends AbstractApiTest {
public void getAccessionsTest() throws Exception {
// Also works with 2000, 5000, 10000, 15000
int amount = 1000;
List<Accession> accessions = setUpAccessions(amount);
assertThat(accessionRepository.count(), is((long)(amount)));
List<UUID> uuids = accessions.stream().map(Accession::getAccessionId).map(AccessionId::getUuid).collect(Collectors.toList());
final String s = objectMapper.writeValueAsString(uuids);
mockMvc.perform(post(org.genesys2.server.api.v1.AccessionController.API_BASE + "/for-uuid")
.contentType(MediaType.APPLICATION_JSON)
.content(s))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(amount)));
int amounts[] = { 10, 99, 100, 101, 1000 };
List<Accession> accessions = setUpAccessions(2000);
assertThat(accessionRepository.count(), is(2000L));
for (int amount: amounts) {
List<UUID> uuids = accessions.subList(0, amount).stream().map(Accession::getAccessionId).map(AccessionId::getUuid).collect(Collectors.toList());
final String s = objectMapper.writeValueAsString(uuids);
/*@formatter:off*/
mockMvc.perform(post(org.genesys2.server.api.v1.AccessionController.API_BASE + "/for-uuid")
.contentType(MediaType.APPLICATION_JSON)
.content(s))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(amount)));
/*@formatter:on*/
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment