处理动态消息查询死循环

This commit is contained in:
梁琦涛
2024-03-25 18:10:36 +08:00
parent abc7967269
commit d7feb7719d
2 changed files with 9 additions and 25 deletions
@@ -179,22 +179,10 @@ public class HomeSearchCheckEsPlanJob implements Job {
}
private void addES(List<String> listIds, String lawsNewsFeed) {
int startIndex = 0; // 从第0个下标开始
int batchCount = 1000;
while (startIndex < listIds.size()) {
int endIndex = 0;
if (listIds.size() - batchCount < startIndex) {
endIndex = listIds.size();
} else {
endIndex = startIndex + batchCount;
}
List<String> ids = listIds.subList(startIndex, endIndex);
try {
lawsHomeSearchService.updateEsData(lawsNewsFeed, String.join(",", ids), LawsHomeSearchCommon.LAWS_ES_ADD);
} catch (Exception e) {
log.error("ES同步异常:", e.getMessage());
}
startIndex = startIndex + batchCount; // 下一批
try {
lawsHomeSearchService.updateEsData(lawsNewsFeed, String.join(",", listIds), LawsHomeSearchCommon.LAWS_ES_ADD);
} catch (Exception e) {
log.error("ES同步异常:", e.getMessage());
}
}
@@ -1410,16 +1410,11 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
private void updateLawsNewsFeedToEs(String resourceType, String ids,String opType) {
// 批量操作
// 从第0个下标开始
int startIndex = 0;
int batchCount = 2000;
List<String> listIds = Arrays.asList(ids.split(","));
// 异步执行
while (startIndex < listIds.size()) {
int endIndex = getEndIndex(startIndex, batchCount, listIds);
List<String> listIdsSub = listIds.subList(startIndex, endIndex);
List<LawsNewsFeed> listLawsNewsFeed = lawsNewsFeedService.listByIds(listIdsSub);
try {
List<LawsNewsFeed> listLawsNewsFeed = lawsNewsFeedService.listByIds(listIds);
if(CollectionUtils.isEmpty(listLawsNewsFeed)){
continue;
return;
}
for (LawsNewsFeed lawsNewsFeed : listLawsNewsFeed) {
try {
@@ -1438,7 +1433,8 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
log.error(SYNC_ES_ERR,e.getMessage());
}
}
startIndex = startIndex + batchCount; // 下一批
}catch (Exception e){
log.error(SYNC_ES_ERR,e.getMessage());
}
}