Project

General

Profile

« Previous | Next » 

Revision 54105

caching metadata load time

View differences:

modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/dsm/dao/MongoLoggerClientImpl.java
6 6
import java.util.function.Function;
7 7
import java.util.stream.Collectors;
8 8

  
9
import com.google.common.collect.Lists;
9 10
import com.google.common.primitives.Ints;
10 11
import com.mongodb.BasicDBObject;
11 12
import com.mongodb.MongoClient;
......
63 64
		log.warn(String.format("getAggregationHistory(dsId = %s): not using cache", dsId));
64 65
		final Datasource conf = config.getDatasource();
65 66
		try {
66
			final Instant loadTime = Instant.parse(
67
					getCollection().find(queryForLastMetadataLoad())
68
							.sort(dbo("system:startHumanDate", -1))
69
							.first()
70
							.getString("system:startHumanDate")
71
							.replaceAll("\\+.*", "Z"));
72 67
			final FindIterable<Document> aggregationDocs = getCollection().find(queryForAggregationHistory(dsId, "(collect|transform)"))
73 68
					.projection(fields)
74 69
					.limit(conf.getMongoQueryLimit())
......
79 74
					.filter(ai -> ai.getNumberOfRecords() >= 0 && StringUtils.isNotBlank(ai.getDate()))
80 75
					.collect(Collectors.toList());
81 76

  
82
			for (final AggregationInfo a : aggregationInfos) {
83
				if (asInstant(a).isBefore(loadTime) && AggregationStage.COLLECT.equals(a.getAggregationStage())) {
84
					a.setIndexedVersion(true);
85
					break;
77
			final Instant loadTime = getLoadTime();
78

  
79
			if (loadTime != null) {
80
				for (final AggregationInfo a : aggregationInfos) {
81
					if (asInstant(a).isBefore(loadTime) && AggregationStage.COLLECT.equals(a.getAggregationStage())) {
82
						a.setIndexedVersion(true);
83
						break;
84
					}
86 85
				}
87 86
			}
88 87

  
......
93 92
	}
94 93

  
95 94
	@Override
95
	@Cacheable("dsm-metadataloadtime-cache")
96
	public Instant getLoadTime() {
97
		log.warn("querying for metadata load time, not using cache");
98
		final Document first = getCollection().find(queryForLastMetadataLoad())
99
				.sort(dbo("system:startHumanDate", -1))
100
				.first();
101

  
102
		if (first == null) {
103
			return null;
104
		}
105

  
106
		final String startDate = (String) first.getOrDefault("system:startHumanDate", "");
107

  
108
		if (StringUtils.isBlank(startDate)) {
109
			return null;
110
		}
111

  
112
		return Instant.parse(startDate.replaceAll("\\+.*", "Z"));
113
	}
114

  
115
	@Override
96 116
	@Deprecated
97 117
	@Cacheable("dsm-firstharvestdate-cache")
98 118
	public String firstHarvestDate(final String dsId) throws DsmException {
......
118 138
	}
119 139

  
120 140
	@Override
121
	@CacheEvict(cacheNames = { "dsm-aggregationhistory-cache", "dsm-firstharvestdate-cache" }, allEntries = true)
141
	@CacheEvict(cacheNames = { "dsm-aggregationhistory-cache", "dsm-firstharvestdate-cache", "dsm-metadataloadtime-cache" }, allEntries = true)
122 142
	public void dropCache() {
123 143
		log.info("dropped dsManager aggregation history cache");
124 144
	}
modules/dnet-openaire-exporter/trunk/src/main/java/eu/dnetlib/openaire/dsm/dao/MongoLoggerClient.java
1 1
package eu.dnetlib.openaire.dsm.dao;
2 2

  
3
import java.time.Instant;
3 4
import java.util.List;
4 5

  
5 6
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
......
9 10

  
10 11
	List<AggregationInfo> getAggregationHistory(final String dsId) throws DsmException;
11 12

  
13
	Instant getLoadTime();
14

  
12 15
	@Deprecated
13 16
	String firstHarvestDate(final String dsId) throws DsmException;
14 17

  
modules/dnet-openaire-exporter/trunk/src/main/resources/ehcache.xml
71 71
		<persistence strategy="localTempSwap" />
72 72
	</cache>
73 73

  
74
	<cache name="dsm-metadataloadtime-cache"
75
		   maxEntriesLocalHeap="1"
76
		   maxEntriesLocalDisk="10"
77
		   eternal="false"
78
		   diskSpoolBufferSizeMB="1"
79
		   timeToIdleSeconds="43200" timeToLiveSeconds="43200"
80
		   memoryStoreEvictionPolicy="LFU"
81
		   transactionalMode="off">
82
		<persistence strategy="localTempSwap" />
83
	</cache>
84

  
74 85
	<cache name="vocabularies-cache"
75 86
	       maxEntriesLocalHeap="1000"
76 87
	       maxEntriesLocalDisk="1000"

Also available in: Unified diff