Skip to content

Commit

Permalink
broker管理页搜索速度优化
Browse files Browse the repository at this point in the history
  • Loading branch information
iamazy committed Oct 9, 2020
1 parent 460f7ed commit abe2de6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
package org.joyqueue.repository;


import org.apache.ibatis.annotations.Param;
import org.joyqueue.model.domain.BrokerGroupRelated;
import org.joyqueue.model.query.QBrokerGroupRelated;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* Created by lining on 16-11-28.
*/
@Repository
public interface BrokerGroupRelatedRepository extends PageRepository<BrokerGroupRelated,QBrokerGroupRelated> {
int updateGroupByGroupId(BrokerGroupRelated brokerGroupRelated);
int deleteByGroupId(long groupId);
List<BrokerGroupRelated> findByBrokerIds(@Param("brokerIds") List<Long> brokerIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
WHERE b.id=#{id}
</select>

<select id="findByBrokerIds" parameterType="long" resultType="BrokerGroupRelated">
<include refid="select"/>
WHERE b.id in
<foreach collection="brokerIds" item="id" index="i" open="(" separator="," close=")">
#{id}
</foreach>
</select>

<select id="findByIds" resultType="BrokerGroupRelated">
<include refid="select"/>
WHERE b.id IN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
import org.joyqueue.model.domain.BrokerGroupRelated;
import org.joyqueue.model.query.QBrokerGroupRelated;

import java.util.List;
import java.util.Map;

/**
* 分组服务
* Created by chenyanying3 on 2018-10-18.
*/
public interface BrokerGroupRelatedService extends PageService<BrokerGroupRelated, QBrokerGroupRelated> {
int updateGroupByGroupId(BrokerGroupRelated brokerGroupRelated);
int deleteByGroupId(long groupId);
Map<Long, String> findByBrokerIds(List<Long> brokerIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
*/
package org.joyqueue.service.impl;

import org.apache.commons.collections.CollectionUtils;
import org.joyqueue.model.domain.BrokerGroupRelated;
import org.joyqueue.model.query.QBrokerGroupRelated;
import org.joyqueue.repository.BrokerGroupRelatedRepository;
import org.joyqueue.service.BrokerGroupRelatedService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* 分组服务实现
* Created by chenyanying3 on 2018-10-18
Expand All @@ -37,4 +43,16 @@ public int updateGroupByGroupId(BrokerGroupRelated brokerGroupRelated) {
public int deleteByGroupId(long groupId) {
return repository.deleteByGroupId(groupId);
}

@Override
public Map<Long, String> findByBrokerIds(List<Long> brokerIds) {
List<BrokerGroupRelated> brokerGroupRelateds = repository.findByBrokerIds(brokerIds);
if (CollectionUtils.isNotEmpty(brokerGroupRelateds)) {
return brokerGroupRelateds.stream()
.filter(brokerGroupRelated -> brokerGroupRelated.getGroup() != null)
.collect(Collectors.toMap(BrokerGroupRelated::getId,
brokerGroupRelated -> brokerGroupRelated.getGroup().getCode()));
}
return Collections.emptyMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.joyqueue.service.BrokerGroupRelatedService;
import org.joyqueue.service.BrokerService;
import org.joyqueue.service.PartitionGroupReplicaService;
import org.joyqueue.toolkit.time.SystemClock;
import org.joyqueue.util.NullUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -236,10 +237,11 @@ private PageResult<Broker> searchMultiKeyword(QPageQuery<QBroker> qPageQuery) th
PageResult<Broker> pageResult = brokerNameServerService.search(qPageQuery);
if (pageResult != null && pageResult.getResult() != null && pageResult.getResult().size() > 0) {
List<Broker> brokerList = pageResult.getResult();
Map<Long, String> brokerGroupMap = brokerGroupRelatedService.findByBrokerIds(brokerList.stream().map(Broker::getId).collect(Collectors.toList()));
for (Broker broker : brokerList) {
BrokerGroupRelated brokerRelated = brokerGroupRelatedService.findById(broker.getId());
if (brokerRelated != null && brokerRelated.getGroup() != null) {
broker.setGroup(brokerRelated.getGroup());
String group = brokerGroupMap.get(broker.getId());
if (StringUtils.isNotBlank(group)) {
broker.setGroup(new Identity(group));
broker.setStatus(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ protected Producer fillProducer(Producer producer) {
app.setName(application.getName());
producer.setOwner(application.getOwner());
}
if (StringUtils.isNotBlank(producer.getConfig().getWeight())) {
String[] split = producer.getConfig().getWeight().split(",");
StringBuilder builder = new StringBuilder();
for (String item: split) {
String[] items = item.split(":");
if (Long.parseLong(items[1]) > 0) {
builder.append(items[0]).append(":").append(items[1]).append(",");
}
}
if (builder.length() > 0) {
builder.deleteCharAt(builder.length() - 1);
producer.getConfig().setWeight(builder.toString());
} else {
producer.getConfig().setWeight(null);
}
}
return producer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ public Response pageQuery(@PageQuery QPageQuery<QProducer> qPageQuery) throws Ex

if (appFlag) {
if (CollectionUtils.isNotEmpty(producers) && session.getRole() != User.UserRole.ADMIN.value()) {
Iterator<Producer> iterator = producers.iterator();
while (iterator.hasNext()) {
Producer producer = iterator.next();
if (applicationUserService.findByUserApp(session.getCode(), producer.getApp().getCode()) == null) {
iterator.remove();
}
}
producers.removeIf(producer -> applicationUserService.findByUserApp(session.getCode(), producer.getApp().getCode()) == null);
}
}

Expand Down

0 comments on commit abe2de6

Please sign in to comment.