(improvement)(Headless) Improve model list performance (#880)

Co-authored-by: jolunoluo
This commit is contained in:
LXW
2024-04-03 18:54:48 +08:00
committed by GitHub
parent 6996c4c12e
commit 12c06c8ebe
16 changed files with 83 additions and 53 deletions

View File

@@ -51,4 +51,6 @@ public class DimensionDO {
private String dataType;
private int isTag;
private String ext;
}

View File

@@ -47,9 +47,15 @@ public class ModelRepositoryImpl implements ModelRepository {
if (!CollectionUtils.isEmpty(modelFilter.getDomainIds())) {
wrapper.lambda().in(ModelDO::getDomainId, modelFilter.getDomainIds());
}
if (modelFilter.getDomainId() != null) {
wrapper.lambda().eq(ModelDO::getDomainId, modelFilter.getDomainId());
}
if (!CollectionUtils.isEmpty(modelFilter.getIds())) {
wrapper.lambda().in(ModelDO::getId, modelFilter.getIds());
}
if (!CollectionUtils.isEmpty(modelFilter.getModelIds())) {
wrapper.lambda().in(ModelDO::getId, modelFilter.getModelIds());
}
if (modelFilter.getIncludesDetail() != null && !modelFilter.getIncludesDetail()) {
wrapper.select(ModelDO.class, modelDO -> !modelDO.getColumn().equals("model_detail"));
}

View File

@@ -34,7 +34,7 @@ public interface ModelService {
List<ModelResp> getModelListWithAuth(User user, Long domainId, AuthType authType);
List<ModelResp> getModelAuthList(User user, AuthType authTypeEnum);
List<ModelResp> getModelAuthList(User user, Long domainId, AuthType authTypeEnum);
List<ModelResp> getModelByDomainIds(List<Long> domainIds);

View File

@@ -105,7 +105,7 @@ public class DomainServiceImpl implements DomainService {
List<Long> domainIds = domainWithAuthAll.stream().map(DomainResp::getId).collect(Collectors.toList());
domainWithAuthAll.addAll(getParentDomain(domainIds));
}
List<ModelResp> modelResps = modelService.getModelAuthList(user, AuthType.ADMIN);
List<ModelResp> modelResps = modelService.getModelAuthList(user, null, AuthType.ADMIN);
if (!CollectionUtils.isEmpty(modelResps)) {
List<Long> domainIds = modelResps.stream().map(ModelResp::getDomainId).collect(Collectors.toList());
domainWithAuthAll.addAll(getParentDomain(domainIds));

View File

@@ -294,25 +294,23 @@ public class ModelServiceImpl implements ModelService {
@Override
public List<ModelResp> getModelListWithAuth(User user, Long domainId, AuthType authType) {
List<ModelResp> modelResps = getModelAuthList(user, authType);
List<ModelResp> modelResps = getModelAuthList(user, domainId, authType);
Set<ModelResp> modelRespSet = new HashSet<>(modelResps);
List<ModelResp> modelRespsAuthInheritDomain = getModelRespAuthInheritDomain(user, authType);
List<ModelResp> modelRespsAuthInheritDomain = getModelRespAuthInheritDomain(user, domainId, authType);
modelRespSet.addAll(modelRespsAuthInheritDomain);
if (domainId != null && domainId > 0) {
modelRespSet = modelRespSet.stream().filter(modelResp ->
modelResp.getDomainId().equals(domainId)).collect(Collectors.toSet());
}
return modelRespSet.stream().sorted(Comparator.comparingLong(ModelResp::getId))
.collect(Collectors.toList());
}
public List<ModelResp> getModelRespAuthInheritDomain(User user, AuthType authType) {
Set<DomainResp> domainResps = domainService.getDomainAuthSet(user, authType);
if (CollectionUtils.isEmpty(domainResps)) {
public List<ModelResp> getModelRespAuthInheritDomain(User user, Long domainId, AuthType authType) {
List<Long> domainIds = domainService.getDomainAuthSet(user, authType)
.stream().map(DomainResp::getId)
.collect(Collectors.toList());
if (domainIds.contains(domainId)) {
domainIds = Lists.newArrayList(domainId);
} else {
return Lists.newArrayList();
}
List<Long> domainIds = domainResps.stream().map(DomainResp::getId)
.collect(Collectors.toList());
ModelFilter modelFilter = new ModelFilter();
modelFilter.setIncludesDetail(false);
modelFilter.setDomainIds(domainIds);
@@ -320,9 +318,10 @@ public class ModelServiceImpl implements ModelService {
}
@Override
public List<ModelResp> getModelAuthList(User user, AuthType authTypeEnum) {
public List<ModelResp> getModelAuthList(User user, Long domainId, AuthType authTypeEnum) {
ModelFilter modelFilter = new ModelFilter();
modelFilter.setIncludesDetail(false);
modelFilter.setDomainId(domainId);
List<ModelResp> modelResps = getModelList(modelFilter);
Set<String> orgIds = userService.getUserAllOrgId(user.getName());
List<ModelResp> modelWithAuth = Lists.newArrayList();

View File

@@ -38,6 +38,9 @@ public class DimensionConverter {
if (Objects.nonNull(dimensionReq.getDataType())) {
dimensionDO.setDataType(dimensionReq.getDataType().getType());
}
if (dimensionReq.getExt() != null) {
dimensionDO.setExt(JSONObject.toJSONString(dimensionReq.getExt()));
}
return dimensionDO;
}
@@ -53,6 +56,9 @@ public class DimensionConverter {
if (Objects.nonNull(dimensionReq.getDataType())) {
dimensionDO.setDataType(dimensionReq.getDataType().getType());
}
if (dimensionReq.getExt() != null) {
dimensionDO.setExt(JSONObject.toJSONString(dimensionReq.getExt()));
}
dimensionDO.setStatus(StatusEnum.ONLINE.getCode());
return dimensionDO;
}
@@ -76,6 +82,9 @@ public class DimensionConverter {
if (Strings.isNotEmpty(dimensionDO.getDataType())) {
dimensionResp.setDataType(DataTypeEnums.of(dimensionDO.getDataType()));
}
if (dimensionDO.getExt() != null) {
dimensionResp.setExt(JSONObject.parseObject(dimensionDO.getExt(), Map.class));
}
dimensionResp.setTypeEnum(TypeEnums.DIMENSION);
return dimensionResp;
}

View File

@@ -3,6 +3,7 @@ package com.tencent.supersonic.headless.server.utils;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.tencent.supersonic.common.pojo.DataFormat;
import com.tencent.supersonic.common.pojo.enums.PublishEnum;
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
import com.tencent.supersonic.common.util.BeanMapper;
@@ -34,7 +35,10 @@ public class MetricConverter {
metricDO.setClassifications(metricReq.getClassifications());
metricDO.setRelateDimensions(JSONObject.toJSONString(metricReq.getRelateDimension()));
metricDO.setStatus(StatusEnum.ONLINE.getCode());
metricDO.setExt(JSONObject.toJSONString(metricReq.getExt()));
metricDO.setIsPublish(PublishEnum.UN_PUBLISHED.getCode());
if (metricReq.getExt() != null) {
metricDO.setExt(JSONObject.toJSONString(metricReq.getExt()));
}
metricDO.setDefineType(metricReq.getMetricDefineType().name());
return metricDO;
}
@@ -80,7 +84,7 @@ public class MetricConverter {
metricResp.setRelateDimension(JSONObject.parseObject(metricDO.getRelateDimensions(),
RelateDimension.class));
if (metricDO.getExt() != null) {
metricResp.setExt(JSONObject.parseObject(metricDO.getExt(), Map.class));
metricResp.setExt(JSONObject.parseObject(metricDO.getExt(), HashMap.class));
}
metricResp.setTypeEnum(TypeEnums.METRIC);
if (MetricDefineType.MEASURE.name().equalsIgnoreCase(metricDO.getDefineType())) {