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 |
}
|
caching metadata load time