Commit ee06c75b authored by Matija Obreza's avatar Matija Obreza

AccessionRefs: relink only newly added records

- Doesn't rescan entire dataset/subset
parent c248fbed
......@@ -628,7 +628,7 @@ public class DatasetServiceImpl implements DatasetService {
TransactionStatus status = transactionManager.getTransaction(def);
try {
// execute your business logic here
rematchDatasetAccessions(loadedDataset);
rematchDatasetAccessions(dArs);
} catch (Throwable ex) {
LOG.error("Rolling back rematch. Exception: {}", ex.getMessage(), ex);
transactionManager.rollback(status);
......@@ -1049,6 +1049,26 @@ public class DatasetServiceImpl implements DatasetService {
LOG.warn("Done relinking {} accession refs.", accessionRefs.size());
return lazyLoad(dataset);
}
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
private List<DatasetAccessionRef> rematchDatasetAccessions(List<DatasetAccessionRef> accessionRefs) {
LOG.warn("Re-linking {} accessions refs with accessions", accessionRefs.size());
final AtomicInteger batchCounter = new AtomicInteger(0);
// Use parallel streams for lookups
Lists.partition(accessionRefs, 1000).parallelStream().forEach(batch -> {
LOG.info("Batch {} with size {}", batchCounter.incrementAndGet(), batch.size());
lookupMatchingAccessions(batch);
});
// Save in this transaction
accessionRefRepository.update(accessionRefs);
LOG.warn("Done relinking {} accession refs.", accessionRefs.size());
return accessionRefs;
}
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_UNCOMMITTED)
......
......@@ -380,7 +380,7 @@ public class SubsetServiceImpl implements SubsetService {
TransactionStatus status = transactionManager.getTransaction(def);
try {
// execute your business logic here
rematchSubsetAccessions(loadedSubset);
rematchSubsetAccessions(sArs);
} catch (Throwable ex) {
LOG.error("Rolling back rematch. Exception: {}", ex.getMessage(), ex);
transactionManager.rollback(status);
......@@ -615,6 +615,24 @@ public class SubsetServiceImpl implements SubsetService {
return lazyLoad(subset);
}
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
private List<SubsetAccessionRef> rematchSubsetAccessions(List<SubsetAccessionRef> accessionRefs) {
LOG.warn("Linking {} accession refs with accessions", accessionRefs.size());
final AtomicInteger batchCounter = new AtomicInteger(0);
// Use parallel streams for lookups
Lists.partition(accessionRefs, 1000).parallelStream().forEach(batch -> {
LOG.info("Batch {} with size {}", batchCounter.incrementAndGet(), batch.size());
lookupMatchingAccessions(batch);
});
// Save in this transaction
accessionRefRepository.update(accessionRefs);
LOG.warn("Done relinking {} accession refs.", accessionRefs.size());
return accessionRefs;
}
/**
* Looking for matching Accession and then sets that to AccessionRef
*
......
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