同步知识库的优化

This commit is contained in:
wangliwen 2022-08-25 17:55:27 +08:00
parent 30b5ee12f0
commit 70c706ba73
1 changed files with 54 additions and 53 deletions

View File

@ -1224,8 +1224,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
if (list.isEmpty() || list.size() < pageSize) { if (list.isEmpty() || list.size() < pageSize) {
end.set(false); end.set(false);
} }
customThreadPool.submit(() -> { customThreadPool.submit(() -> list.parallelStream().filter(resource -> {
list.parallelStream().filter(resource -> {
Map<String, Object> map = (Map<String, Object>) resource; Map<String, Object> map = (Map<String, Object>) resource;
return !knowledgeUUID.contains(map.get("uuid").toString()); return !knowledgeUUID.contains(map.get("uuid").toString());
}).forEach(resource -> { }).forEach(resource -> {
@ -1272,16 +1271,18 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
dto.setInfoList(infoList); dto.setInfoList(infoList);
this.insertWithAttrs(dto); this.insertWithAttrs(dto);
logger.info("插入:{}", dto.getName()); logger.info("插入:{}", dto.getName());
}); })).join();
}).join();
customThreadPool.shutdown(); customThreadPool.shutdown();
}, executor)); }, executor));
if (maxPage.get() == 100) {
try { try {
Thread.sleep(100L); // 防止任务运行过快无法跳出循环 Thread.sleep(new Random().nextInt(100)); // 防止任务运行过快无法跳出循环
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.info("知识库同步异常", e); logger.info("知识库同步异常", e);
// throw new RuntimeException(e);
} }
}
} while (end.get() || pageIndex.get() < maxPage.get()); } while (end.get() || pageIndex.get() < maxPage.get());
return task; return task;
}).collect(Collectors.toList()); }).collect(Collectors.toList());