(improvement)(headless)Decrease the number of database queries to the s2_domain table. #1472

This commit is contained in:
jerryjzhang
2024-08-08 20:59:31 +08:00
parent 1608317ab3
commit f06cd0b296
5 changed files with 19 additions and 20 deletions

View File

@@ -119,25 +119,21 @@ public class DomainServiceImpl implements DomainService {
public Set<DomainResp> getDomainAuthSet(User user, AuthType authTypeEnum) { public Set<DomainResp> getDomainAuthSet(User user, AuthType authTypeEnum) {
List<DomainResp> domainResps = getDomainList(); List<DomainResp> domainResps = getDomainList();
Set<String> orgIds = userService.getUserAllOrgId(user.getName()); Set<String> orgIds = userService.getUserAllOrgId(user.getName());
List<DomainResp> domainWithAuth = Lists.newArrayList(); Set<DomainResp> domainWithAuth = Sets.newHashSet();
if (authTypeEnum.equals(AuthType.ADMIN)) { if (authTypeEnum.equals(AuthType.ADMIN)) {
domainWithAuth = domainResps.stream() domainWithAuth = domainResps.stream()
.filter(domainResp -> checkAdminPermission(orgIds, user, domainResp)) .filter(domainResp -> checkAdminPermission(orgIds, user, domainResp))
.collect(Collectors.toList()); .collect(Collectors.toSet());
} }
if (authTypeEnum.equals(AuthType.VISIBLE)) { if (authTypeEnum.equals(AuthType.VISIBLE)) {
domainWithAuth = domainResps.stream() domainWithAuth = domainResps.stream()
.filter(domainResp -> checkViewPermission(orgIds, user, domainResp)) .filter(domainResp -> checkViewPermission(orgIds, user, domainResp))
.collect(Collectors.toList());
}
List<Long> domainIds = domainWithAuth.stream().map(DomainResp::getId)
.collect(Collectors.toList());
//get all child domain
return getDomainChildren(domainIds).stream()
.peek(domainResp -> domainResp.setHasEditPermission(true))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
return domainWithAuth;
}
private Set<DomainResp> getParentDomain(List<Long> ids) { private Set<DomainResp> getParentDomain(List<Long> ids) {
Set<DomainResp> domainSet = new HashSet<>(); Set<DomainResp> domainSet = new HashSet<>();
if (CollectionUtils.isEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) {

View File

@@ -358,9 +358,9 @@ public class ModelServiceImpl implements ModelService {
if (modelDO == null) { if (modelDO == null) {
return null; return null;
} }
Map<Long, DomainResp> domainRespMap = domainService.getDomainList().stream()
.collect(Collectors.toMap(DomainResp::getId, d -> d)); DomainResp domainResp = domainService.getDomain(modelDO.getDomainId());
return ModelConverter.convert(modelDO, domainRespMap); return ModelConverter.convert(modelDO, domainResp);
} }
@Override @Override

View File

@@ -70,9 +70,8 @@ public class ModelConverter {
return modelResp; return modelResp;
} }
public static ModelResp convert(ModelDO modelDO, Map<Long, DomainResp> domainRespMap) { public static ModelResp convert(ModelDO modelDO, DomainResp domainResp) {
ModelResp modelResp = convert(modelDO); ModelResp modelResp = convert(modelDO);
DomainResp domainResp = domainRespMap.get(modelResp.getDomainId());
if (domainResp != null) { if (domainResp != null) {
String fullBizNamePath = domainResp.getFullPath() + modelResp.getBizName(); String fullBizNamePath = domainResp.getFullPath() + modelResp.getBizName();
modelResp.setFullPath(fullBizNamePath); modelResp.setFullPath(fullBizNamePath);

View File

@@ -1,4 +1,9 @@
s2: s2:
schema:
cache:
enable: true
parser: parser:
strategy: ONE_PASS_SELF_CONSISTENCY strategy: ONE_PASS_SELF_CONSISTENCY
exemplar-recall: exemplar-recall:

View File

@@ -1,4 +1,9 @@
s2: s2:
schema:
cache:
enable: false
parser: parser:
strategy: ONE_PASS_SELF_CONSISTENCY strategy: ONE_PASS_SELF_CONSISTENCY
exemplar-recall: exemplar-recall:
@@ -15,16 +20,10 @@ s2:
information: true information: true
date: true date: true
demo: demo:
names: S2VisitsDemo,S2ArtistDemo names: S2VisitsDemo,S2ArtistDemo
enableLLM: false enableLLM: false
schema:
cache:
enable: false
authentication: authentication:
enable: true enable: true
exclude: exclude: