处理动态消息查询死循环
This commit is contained in:
+4
-16
@@ -179,22 +179,10 @@ public class HomeSearchCheckEsPlanJob implements Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addES(List<String> listIds, String lawsNewsFeed) {
|
private void addES(List<String> listIds, String lawsNewsFeed) {
|
||||||
int startIndex = 0; // 从第0个下标开始
|
try {
|
||||||
int batchCount = 1000;
|
lawsHomeSearchService.updateEsData(lawsNewsFeed, String.join(",", listIds), LawsHomeSearchCommon.LAWS_ES_ADD);
|
||||||
while (startIndex < listIds.size()) {
|
} catch (Exception e) {
|
||||||
int endIndex = 0;
|
log.error("ES同步异常:", e.getMessage());
|
||||||
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; // 下一批
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-9
@@ -1410,16 +1410,11 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
|
|||||||
private void updateLawsNewsFeedToEs(String resourceType, String ids,String opType) {
|
private void updateLawsNewsFeedToEs(String resourceType, String ids,String opType) {
|
||||||
// 批量操作
|
// 批量操作
|
||||||
// 从第0个下标开始
|
// 从第0个下标开始
|
||||||
int startIndex = 0;
|
|
||||||
int batchCount = 2000;
|
|
||||||
List<String> listIds = Arrays.asList(ids.split(","));
|
List<String> listIds = Arrays.asList(ids.split(","));
|
||||||
// 异步执行
|
try {
|
||||||
while (startIndex < listIds.size()) {
|
List<LawsNewsFeed> listLawsNewsFeed = lawsNewsFeedService.listByIds(listIds);
|
||||||
int endIndex = getEndIndex(startIndex, batchCount, listIds);
|
|
||||||
List<String> listIdsSub = listIds.subList(startIndex, endIndex);
|
|
||||||
List<LawsNewsFeed> listLawsNewsFeed = lawsNewsFeedService.listByIds(listIdsSub);
|
|
||||||
if(CollectionUtils.isEmpty(listLawsNewsFeed)){
|
if(CollectionUtils.isEmpty(listLawsNewsFeed)){
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
for (LawsNewsFeed lawsNewsFeed : listLawsNewsFeed) {
|
for (LawsNewsFeed lawsNewsFeed : listLawsNewsFeed) {
|
||||||
try {
|
try {
|
||||||
@@ -1438,7 +1433,8 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
|
|||||||
log.error(SYNC_ES_ERR,e.getMessage());
|
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