Optimize general metric counter
This commit is contained in:
parent
11ff99fd77
commit
d16e130dc6
|
@ -3,7 +3,6 @@ package eu.eudat.logic.managers;
|
||||||
import eu.eudat.data.dao.criteria.*;
|
import eu.eudat.data.dao.criteria.*;
|
||||||
import eu.eudat.data.entities.DatasetProfile;
|
import eu.eudat.data.entities.DatasetProfile;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
|
|
||||||
import eu.eudat.types.MetricNames;
|
import eu.eudat.types.MetricNames;
|
||||||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||||
import io.prometheus.client.Gauge;
|
import io.prometheus.client.Gauge;
|
||||||
|
@ -23,7 +22,10 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.*;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -402,17 +404,10 @@ public class MetricsManager {
|
||||||
criteria.setStatus(1);
|
criteria.setStatus(1);
|
||||||
criteria.setAllVersions(false);
|
criteria.setAllVersions(false);
|
||||||
if (countNexus) criteria.setPeriodStart(getNexusDate());
|
if (countNexus) criteria.setPeriodStart(getNexusDate());
|
||||||
List<DatasetProfile> datasetProfiles = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).toList();
|
List<DatasetProfile> datasetProfiles = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).withFields(Collections.singletonList("id")).toList();
|
||||||
List<DatasetProfile> filteredProfiles = new ArrayList<>();
|
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||||
for (DatasetProfile datasetProfile : datasetProfiles) {
|
datasetCriteria.setDatasetTemplates(datasetProfiles.stream().map(DatasetProfile::getId).collect(Collectors.toList()));
|
||||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> root.getProfile().getId()).stream().distinct().count();
|
||||||
datasetCriteria.setDatasetTemplates(Collections.singletonList(datasetProfile.getId()));
|
|
||||||
Long datasetCount = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).count();
|
|
||||||
if (datasetCount > 0) {
|
|
||||||
filteredProfiles.add(datasetProfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredProfiles.stream().filter(StreamDistinctBy.distinctByKey(DatasetProfile::getId)).count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue