Optimize UI queries (#1234)

* first iteration of query optimization for target and distribution set
* fixed type distribution set filter
* adapted all ui dataproviders to use repository count
* adapted test to not check target attributes within search query
* unified search behaviuor for ds and sm
* removed unneccessary count queries for some mgmt calls
* removed unneccessary type id proprty from ProxyDistributionSetInfo to minimize lazy fetches
* refactored mgmt classes
* removed duplication of name version filter
* fixed copy rollout compatibility check
* cleaned-up management left overs
* added index to rollouts table on tenant/status queries

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch.io>
This commit is contained in:
Bondar Bogdan
2022-03-23 09:08:56 +01:00
committed by GitHub
parent 681df6c1f1
commit c9eafbbc26
74 changed files with 1444 additions and 1617 deletions

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.ValidationException;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
@@ -83,15 +84,15 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<Rollout> findModulesAll;
final Page<Rollout> findRolloutsAll;
if (rsqlParam != null) {
findModulesAll = this.rolloutManagement.findByRsql(pageable, rsqlParam, false);
findRolloutsAll = this.rolloutManagement.findByRsql(pageable, rsqlParam, false);
} else {
findModulesAll = this.rolloutManagement.findAll(pageable, false);
findRolloutsAll = this.rolloutManagement.findAll(pageable, false);
}
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(findModulesAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, findModulesAll.getTotalElements()));
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(findRolloutsAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, findRolloutsAll.getTotalElements()));
}
@Override
@@ -114,16 +115,15 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
throw new RSQLParameterSyntaxException("Cannot create a Rollout with an empty target query filter!");
}
targetFilterQueryManagement.verifyTargetFilterQuerySyntax(targetFilterQuery);
final DistributionSet distributionSet = distributionSetManagement.getValidAndComplete(
rolloutRequestBody.getDistributionSetId());
final DistributionSet distributionSet = distributionSetManagement
.getValidAndComplete(rolloutRequestBody.getDistributionSetId());
final RolloutGroupConditions rolloutGroupConditions = MgmtRolloutMapper.fromRequest(rolloutRequestBody, true);
final RolloutCreate create = MgmtRolloutMapper.fromRequest(entityFactory, rolloutRequestBody, distributionSet);
Rollout rollout;
if (rolloutRequestBody.getGroups() != null) {
final List<RolloutGroupCreate> rolloutGroups = rolloutRequestBody.getGroups()
.stream()
final List<RolloutGroupCreate> rolloutGroups = rolloutRequestBody.getGroups().stream()
.map(mgmtRolloutGroup -> MgmtRolloutMapper.fromRequest(entityFactory, mgmtRolloutGroup))
.collect(Collectors.toList());
rollout = rolloutManagement.create(create, rolloutGroups, rolloutGroupConditions);

View File

@@ -106,12 +106,11 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
final Slice<Target> findTargetsAll;
final long countTargetsAll;
if (rsqlParam != null) {
final Page<Target> findTargetPage = this.targetManagement.findByRsql(pageable, rsqlParam);
countTargetsAll = findTargetPage.getTotalElements();
findTargetsAll = findTargetPage;
findTargetsAll = targetManagement.findByRsql(pageable, rsqlParam);
countTargetsAll = targetManagement.countByRsql(rsqlParam);
} else {
findTargetsAll = this.targetManagement.findAll(pageable);
countTargetsAll = this.targetManagement.count();
findTargetsAll = targetManagement.findAll(pageable);
countTargetsAll = targetManagement.count();
}
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent());
@@ -165,7 +164,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
@Override
public ResponseEntity<Void> assignTargetType(@PathVariable("targetId") final String targetId, @RequestBody final MgmtId targetTypeId) {
public ResponseEntity<Void> assignTargetType(@PathVariable("targetId") final String targetId,
@RequestBody final MgmtId targetTypeId) {
this.targetManagement.assignType(targetId, targetTypeId.getId());
return ResponseEntity.ok().build();
}
@@ -304,8 +304,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
final List<Entry<String, Long>> offlineAssignments = dsAssignments.stream()
.map(dsAssignment -> new SimpleEntry<String, Long>(targetId, dsAssignment.getId()))
.collect(Collectors.toList());
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(
deploymentManagement.offlineAssignedDistributionSets(offlineAssignments)));
return ResponseEntity.ok(MgmtDistributionSetMapper
.toResponse(deploymentManagement.offlineAssignedDistributionSets(offlineAssignments)));
}
findTargetWithExceptionIfNotFound(targetId);

View File

@@ -150,18 +150,15 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
Page<Target> findTargetsAll;
final Page<Target> findTargetsAll;
if (rsqlParam == null) {
findTargetsAll = targetManagement.findByTag(pageable, targetTagId);
} else {
findTargetsAll = targetManagement.findByRsqlAndTag(pageable, rsqlParam, targetTagId);
}
final Long countTargetsAll = findTargetsAll.getTotalElements();
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, countTargetsAll));
return ResponseEntity.ok(new PagedList<>(rest, findTargetsAll.getTotalElements()));
}
@Override

View File

@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyP
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetTypeManagement;
@@ -48,7 +47,7 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
private final TargetTypeManagement targetTypeManagement;
private final EntityFactory entityFactory;
public MgmtTargetTypeResource(TargetTypeManagement targetTypeManagement, final EntityFactory entityFactory) {
public MgmtTargetTypeResource(final TargetTypeManagement targetTypeManagement, final EntityFactory entityFactory) {
this.targetTypeManagement = targetTypeManagement;
this.entityFactory = entityFactory;
}
@@ -65,14 +64,15 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
final Sort sorting = PagingUtility.sanitizeTargetTypeSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<TargetType> findTargetTypesAll;
final Slice<TargetType> findTargetTypesAll;
long countTargetTypesAll;
if (rsqlParam != null) {
findTargetTypesAll= targetTypeManagement.findByRsql(pageable, rsqlParam);
findTargetTypesAll = targetTypeManagement.findByRsql(pageable, rsqlParam);
countTargetTypesAll = ((Page<TargetType>) findTargetTypesAll).getTotalElements();
} else {
findTargetTypesAll = targetTypeManagement.findAll(pageable);
countTargetTypesAll = targetTypeManagement.count();
}
countTargetTypesAll = findTargetTypesAll.getTotalElements();
final List<MgmtTargetType> rest = MgmtTargetTypeMapper.toListResponse(findTargetTypesAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, countTargetTypesAll));
@@ -135,8 +135,8 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
public ResponseEntity<Void> addCompatibleDistributionSets(@PathVariable("targetTypeId") final Long targetTypeId,
@RequestBody final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds) {
targetTypeManagement.assignCompatibleDistributionSetTypes(targetTypeId,
distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()));
targetTypeManagement.assignCompatibleDistributionSetTypes(targetTypeId, distributionSetTypeIds.stream()
.map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()));
return ResponseEntity.ok().build();
}