diff --git a/src/test/java/test/application/common/MyProvider.java b/src/test/java/test/application/common/MyProvider.java index 315ce4c..64768f8 100644 --- a/src/test/java/test/application/common/MyProvider.java +++ b/src/test/java/test/application/common/MyProvider.java @@ -1,11 +1,16 @@ package test.application.common; import com.houkunlin.system.dict.starter.bean.DictTypeVo; +import com.houkunlin.system.dict.starter.bean.DictValueVo; import com.houkunlin.system.dict.starter.provider.DictProvider; +import lombok.AllArgsConstructor; +import lombok.Data; import org.springframework.stereotype.Component; +import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; +import java.util.List; /** * @author HouKunLin @@ -19,10 +24,28 @@ public boolean isStoreDictType() { @Override public Iterator dictTypeIterator() { - final DictTypeVo typeVo = DictTypeVo.newBuilder("name", "测试字典") - .add("1", "测试1") - .add("2", "测试2") + long startTime = System.nanoTime(); + List users = new ArrayList<>(); + for (int i = 0; i < 1586; i++) { + users.add(new DictUser(i, "名称" + i)); + } + System.out.println("加载用户数据耗时:" + (System.nanoTime() - startTime) / 100_0000.0 + "ms"); + startTime = System.nanoTime(); + final DictTypeVo typeVo = DictTypeVo.newBuilder("DictUser", "DictUser") .build(); + List children = typeVo.getChildren(); + users.forEach(dictUser -> { + DictValueVo valueVo = new DictValueVo("DictUser", dictUser.getId(), dictUser.getName(), 0); + children.add(valueVo); + }); + System.out.println("转换用户数据耗时:" + (System.nanoTime() - startTime) / 100_0000.0 + "ms"); return Collections.singletonList(typeVo).iterator(); } } + +@Data +@AllArgsConstructor +class DictUser { + private int id; + private String name; +} diff --git a/src/test/java/test/application/common/ScheduledRefreshDicEvent.java b/src/test/java/test/application/common/ScheduledRefreshDicEvent.java index 9d7293c..62e8444 100644 --- a/src/test/java/test/application/common/ScheduledRefreshDicEvent.java +++ b/src/test/java/test/application/common/ScheduledRefreshDicEvent.java @@ -1,12 +1,17 @@ package test.application.common; +import com.houkunlin.system.dict.starter.bean.DictValueVo; import com.houkunlin.system.dict.starter.notice.RefreshDictEvent; +import com.houkunlin.system.dict.starter.notice.RefreshDictValueEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Scheduled; +import java.util.ArrayList; +import java.util.List; + /** * @author HouKunLin */ @@ -24,5 +29,45 @@ public void refreshDicEvent() { logger.info("开始定时刷新事件"); publisher.publishEvent(new RefreshDictEvent("定时刷新字典:" + System.currentTimeMillis(), true, false)); logger.info("结束定时刷新事件"); + + + long startTime = System.nanoTime(); + for (int i = 0; i < 1000; i++) { + publisher.publishEvent(new RefreshDictValueEvent(DictValueVo.builder().dictType("DictUser").value("" + i).title("昵称" + i).build(), false)); + } + logger.info("单条数据刷新1000次耗时:{} ms", (System.nanoTime() - startTime) / 100_0000.0); + + + startTime = System.nanoTime(); + List list = new ArrayList<>(); + for (int i = 0; i < 1000; i++) { + list.add(DictValueVo.builder().dictType("DictUser").value("" + i).title("昵称" + i).build()); + } + publisher.publishEvent(new RefreshDictValueEvent(list, false)); + logger.info("批量数据刷新1000次耗时:{} ms", (System.nanoTime() - startTime) / 100_0000.0); + + + list = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + list.add(DictValueVo.builder().dictType("DictUser").value("" + i).title("昵称" + i).build()); + } + startTime = System.nanoTime(); + int x = 1000 / list.size() + 1; + for (int i = 0; i < x; i++) { + publisher.publishEvent(new RefreshDictValueEvent(list, false)); + } + logger.info("批量数据刷新 {} 条数据耗时(默认):{} ms", list.size(), (System.nanoTime() - startTime) / 100_0000.0); + + + for (int i = 10; i < 20; i++) { + list.add(DictValueVo.builder().dictType("DictUser").value("" + i).title("昵称" + i).build()); + } + startTime = System.nanoTime(); + for (int i = 0; i < x; i++) { + publisher.publishEvent(new RefreshDictValueEvent(list, false)); + } + logger.info("批量数据刷新 {} 条数据耗时(批量):{} ms", list.size(), (System.nanoTime() - startTime) / 100_0000.0); + + logger.info("结束定时刷新事件"); } }