处理动态消息查询死循环
This commit is contained in:
+4
-16
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-9
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user