Commit 088a805d authored by Matija Obreza's avatar Matija Obreza

Batch update PDCI

parent 54768777
...@@ -235,4 +235,6 @@ public interface GenesysService { ...@@ -235,4 +235,6 @@ public interface GenesysService {
PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute); PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute);
void updatePDCI(Set<Long> accessionIds);
} }
...@@ -1572,6 +1572,25 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1572,6 +1572,25 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return repoPdci.save(pdciCalculator.updatePdci(pdci, accessionId)); return repoPdci.save(pdciCalculator.updatePdci(pdci, accessionId));
} }
@Override
@Transactional
public void updatePDCI(Set<Long> accessionIds) {
if (pdciCalculator == null) {
return;
}
List<PDCI> pdcis = new ArrayList<PDCI>();
for (Long accessionId : accessionIds) {
PDCI pdci = repoPdci.findByAccessionId(accessionId);
if (pdci == null) {
pdci = new PDCI();
pdci.setAccession(accessionIdRepository.findOne(accessionId));
}
pdcis.add(pdciCalculator.updatePdci(pdci, accessionId));
}
repoPdci.save(pdcis);
}
@Override @Override
public PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute) { public PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute) {
PDCIStatistics stats = new PDCIStatistics(); PDCIStatistics stats = new PDCIStatistics();
......
...@@ -111,6 +111,11 @@ class ElasticUpdaterProcessor implements Runnable, InitializingBean, DisposableB ...@@ -111,6 +111,11 @@ class ElasticUpdaterProcessor implements Runnable, InitializingBean, DisposableB
for (String className : buckets.keySet()) { for (String className : buckets.keySet()) {
Set<Long> bucket = buckets.get(className); Set<Long> bucket = buckets.get(className);
// If Accession, update PDCI
if (Accession.class.getName().equals(className)) {
genesysService.updatePDCI(bucket);
}
elasticService.updateAll(className, bucket); elasticService.updateAll(className, bucket);
bucket.clear(); bucket.clear();
} }
...@@ -136,17 +141,17 @@ class ElasticUpdaterProcessor implements Runnable, InitializingBean, DisposableB ...@@ -136,17 +141,17 @@ class ElasticUpdaterProcessor implements Runnable, InitializingBean, DisposableB
String className = toUpdate.getClassName(); String className = toUpdate.getClassName();
// If Accession, update PDCI
if (Accession.class.getName().equals(className)) {
genesysService.updatePDCI(toUpdate.getId());
}
Set<Long> bucket = buckets.get(className); Set<Long> bucket = buckets.get(className);
if (bucket == null) { if (bucket == null) {
buckets.put(className, bucket = new HashSet<Long>()); buckets.put(className, bucket = new HashSet<Long>());
} }
bucket.add(toUpdate.getId()); bucket.add(toUpdate.getId());
if (bucket.size() >= BATCH_SIZE) { if (bucket.size() >= BATCH_SIZE) {
// If Accession, update PDCI
if (Accession.class.getName().equals(className)) {
genesysService.updatePDCI(bucket);
}
elasticService.updateAll(className, bucket); elasticService.updateAll(className, bucket);
bucket.clear(); bucket.clear();
} }
......
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