Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化获取widget的关联信息,修改为批量从数据获取到关联信息 #2040

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public interface RelWidgetElementMapperExt extends RelWidgetElementMapper {
})
List<RelWidgetElement> listWidgetElements(String widgetId);

@Select({
"<script>",
"SELECT * FROM rel_widget_element WHERE widget_id IN " +
"<foreach collection='widgetIds' item='item' index='index' open='(' close=')' separator=','> " +
" #{item} " +
"</foreach>",
"</script>"
})
List<RelWidgetElement> listWidgetElementsByIds(@Param("widgetIds") List<String> widgetId);

@Insert({
"<script>",
"INSERT INTO rel_widget_element (id, widget_id, rel_type, rel_id) VALUES " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ public interface RelWidgetWidgetMapperExt extends RelWidgetWidgetMapper {
})
List<RelWidgetWidget> listTargetWidgets(String sourceId);

@Select({
"<script>",
"SELECT rww.* " +
"FROM rel_widget_widget rww " +
"WHERE rww.source_id IN " +
"<foreach collection='sourceIds' item='item' index='index' open='(' close=')' separator=','> #{item} </foreach> ;",
"</script>",
})
List<RelWidgetWidget> listTargetWidgetsByIds(List<String> sourceIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,29 @@ public boolean update(BaseUpdateParam updateParam) {
}

private List<WidgetDetail> getWidgets(String dashboardId, Set<String> datachartIds, Set<String> viewIds) {
List<String> widgetIds = new ArrayList<>();

// get all widgets details
List<Widget> widgets = widgetMapper.listByDashboard(dashboardId);
List<WidgetDetail> widgetDetails = widgets.stream().map(widget -> {
WidgetDetail widgetDetail = new WidgetDetail();
BeanUtils.copyProperties(widget, widgetDetail);
widgetDetail.setViewIds(new LinkedList<>());
widgetDetail.setRelations(new LinkedList<>());
widgetIds.add(widgetDetail.getId());
return widgetDetail;
}).collect(Collectors.toList());

if (CollectionUtils.isEmpty(widgetIds)) {
return new ArrayList<>(0);
}
Map<String, List<RelWidgetWidget>> relWidgetWidgetsMap = rwwMapper.listTargetWidgetsByIds(widgetIds).stream().collect(Collectors.groupingBy(RelWidgetWidget::getSourceId));
Map<String, List<RelWidgetElement>> elementsMap = rweMapper.listWidgetElementsByIds(widgetIds).stream().collect(Collectors.groupingBy(RelWidgetElement::getWidgetId));


for (WidgetDetail widgetDetail : widgetDetails) {
widgetDetail.setRelations(rwwMapper.listTargetWidgets(widgetDetail.getId()));
List<RelWidgetElement> elements = rweMapper.listWidgetElements(widgetDetail.getId());
widgetDetail.setRelations(Optional.ofNullable(relWidgetWidgetsMap.get(widgetDetail.getId())).orElse(new ArrayList<>(0)));
List<RelWidgetElement> elements = Optional.ofNullable(elementsMap.get(widgetDetail.getId())).orElse(new ArrayList<>(0));
for (RelWidgetElement element : elements) {
if (ResourceType.DATACHART.name().equals(element.getRelType())) {
if (datachartIds != null) {
Expand Down