Commit 6406d81f authored by Matija Obreza's avatar Matija Obreza
Browse files

Don’t evict caches on update, let them expire naturally

parent d818569a
......@@ -38,6 +38,10 @@ import java.util.zip.ZipOutputStream;
import javax.persistence.EntityManager;
import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper;
import com.opencsv.ResultSetHelperService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.StringUtils;
......@@ -107,7 +111,6 @@ import org.genesys2.spring.SecurityContextUtil;
import org.genesys2.util.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Page;
......@@ -123,10 +126,6 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper;
import com.opencsv.ResultSetHelperService;
@Service
@Transactional(readOnly = true)
public class GenesysServiceImpl implements GenesysService, DatasetService {
......@@ -712,7 +711,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionCountryRefs() {
genesysLowlevelRepository.updateCountryRefs();
}
......@@ -720,14 +719,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionInstitueRefs() {
genesysLowlevelRepository.updateFaoInstituteRefs();
}
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionCount(FaoInstitute institute) {
if (institute == null)
return;
......@@ -742,14 +741,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Deprecated
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void addAccessions(List<Accession> accessions) {
accessionRepository.save(accessions);
}
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<Accession> saveAccessions(FaoInstitute institute, List<Accession> accessions) {
if (LOG.isDebugEnabled()) {
LOG.debug("Saving " + accessions.size() + " accessions");
......@@ -761,7 +760,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public AccessionData saveAccession(AccessionData accession) {
if (LOG.isDebugEnabled())
LOG.debug("Updating " + accession);
......@@ -778,7 +777,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<Accession> saveAccessions(Iterable<Accession> accessions) {
Set<FaoInstitute> institutes = new HashSet<FaoInstitute>();
for (Accession accession : accessions) {
......@@ -795,7 +794,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'DELETE') or hasPermission(#institute, 'ADMINISTRATION')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionHistoric> removeAccessions(FaoInstitute institute, List<Accession> toDelete) {
List<AccessionHistoric> deleted = new ArrayList<AccessionHistoric>();
......@@ -842,7 +841,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
// Worker threads don't carry this information
// @PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbardDeposits) {
if (CollectionUtils.isEmpty(svalbardDeposits)) {
return svalbardDeposits;
......@@ -890,7 +889,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionCollect> saveCollecting(List<AccessionCollect> all) {
accessionCollectRepository.save(all);
return all;
......@@ -898,7 +897,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionCollect> removeCollecting(List<AccessionCollect> all) {
accessionCollectRepository.delete(all);
return all;
......@@ -906,7 +905,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionGeo> saveGeo(List<AccessionGeo> all) {
accessionGeoRepository.save(all);
return all;
......@@ -914,7 +913,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionGeo> removeGeo(List<AccessionGeo> all) {
accessionGeoRepository.delete(all);
return all;
......@@ -922,7 +921,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionBreeding> saveBreeding(List<AccessionBreeding> all) {
accessionBreedingRepository.save(all);
return all;
......@@ -930,7 +929,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionBreeding> removeBreeding(List<AccessionBreeding> all) {
accessionBreedingRepository.delete(all);
return all;
......@@ -938,7 +937,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionExchange> saveExchange(List<AccessionExchange> all) {
accessionExchangeRepository.save(all);
return all;
......@@ -946,7 +945,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionExchange> removeExchange(List<AccessionExchange> all) {
accessionExchangeRepository.delete(all);
return all;
......@@ -954,7 +953,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionRemark> saveRemarks(List<AccessionRemark> toSaveRemarks) {
accessionRemarkRepository.save(toSaveRemarks);
return toSaveRemarks;
......@@ -962,7 +961,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionRemark> removeRemarks(List<AccessionRemark> toRemoveRemarks) {
accessionRemarkRepository.delete(toRemoveRemarks);
return toRemoveRemarks;
......@@ -1003,7 +1002,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public Metadata addDataset(FaoInstitute institute, String title, String description) {
final Metadata metadata = new Metadata();
metadata.setInstituteCode(institute.getCode());
......@@ -1031,7 +1030,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#metadata, 'WRITE')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void upsertAccessionData(Metadata metadata, AccessionId accession, Map<Long, List<Object>> methodValues) {
// // Load all existing records for metadata+accession
// List<AccessionTrait> existingEntries =
......@@ -1487,14 +1486,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void refreshMetadataMethods() {
genesysLowlevelRepository.refreshMetadataMethods();
}
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionAlias> saveAliases(List<AccessionAlias> aliases) {
if (aliases.size() > 0) {
accessionAliasRepository.save(aliases);
......@@ -1504,7 +1503,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionAlias> removeAliases(List<AccessionAlias> aliases) {
if (aliases.size() > 0) {
accessionAliasRepository.delete(aliases);
......@@ -1515,7 +1514,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void upsertAliases(long accessionId, String acceNames, String otherIds) {
final AccessionData accession = getAccession(accessionId);
if (accession == null) {
......@@ -1607,7 +1606,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public Set<Long> removeAliases(Set<Long> toRemove) {
for (final Long id : toRemove) {
this.accessionAliasRepository.delete(id);
......@@ -1665,7 +1664,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<PDCI> updatePDCI(final Set<Long> ids) {
if (LOG.isDebugEnabled())
LOG.debug("Calculating PDCI for " + ids.size() + " accessions");
......@@ -1689,7 +1688,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
public PDCI updatePDCI(Long accessionId) {
if (pdciCalculator == null || accessionId == null) {
return null;
......
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