mirror of
https://github.com/201206030/novel-plus.git
synced 2025-06-24 04:46:37 +00:00
1优化es导入策略,2增加默认图片,在读取网络图片失败时设置,防止一直失败重试
This commit is contained in:
@ -43,13 +43,12 @@ public class BookToEsSchedule {
|
||||
private boolean lock = false;
|
||||
|
||||
/**
|
||||
* 5秒导入一次
|
||||
* 1分钟导入一次
|
||||
*/
|
||||
@Scheduled(fixedRate = 1000 * 5)
|
||||
@Scheduled(fixedRate = 1000 * 60)
|
||||
public void saveToEs() {
|
||||
if (!lock) {
|
||||
lock = true;
|
||||
Date currentDate = new Date();
|
||||
try {
|
||||
//查询需要更新的小说
|
||||
Date lastDate = (Date) cacheService.getObject(CacheKey.ES_LAST_UPDATE_TIME);
|
||||
@ -58,10 +57,9 @@ public class BookToEsSchedule {
|
||||
}
|
||||
|
||||
long count ;
|
||||
int page = 1;
|
||||
do {
|
||||
|
||||
List<Book> books = bookService.queryBookByUpdateTimeByPage(lastDate, currentDate,page,100);
|
||||
List<Book> books = bookService.queryBookByUpdateTimeByPage(lastDate,100);
|
||||
for(Book book : books) {
|
||||
//导入到ES
|
||||
EsBookVO esBookVO = new EsBookVO();
|
||||
@ -71,14 +69,15 @@ public class BookToEsSchedule {
|
||||
|
||||
jestClient.execute(action);
|
||||
|
||||
lastDate = book.getUpdateTime();
|
||||
|
||||
}
|
||||
|
||||
count = books.size();
|
||||
page++;
|
||||
|
||||
}while (count == 100);
|
||||
|
||||
cacheService.setObject(CacheKey.ES_LAST_UPDATE_TIME, currentDate);
|
||||
cacheService.setObject(CacheKey.ES_LAST_UPDATE_TIME, lastDate);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
|
@ -231,10 +231,8 @@ public interface BookService {
|
||||
/**
|
||||
* 根据更新时间分页查询书籍列表
|
||||
* @param startDate 开始时间,包括该时间
|
||||
* @param endDate 结束时间,不包括该时间
|
||||
* @param page 页码
|
||||
* @param pageSize 每页数量
|
||||
* @param limit 查询数量
|
||||
* @return 书籍列表
|
||||
* */
|
||||
List<Book> queryBookByUpdateTimeByPage(Date startDate, Date endDate, int page, int pageSize);
|
||||
List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit);
|
||||
}
|
||||
|
@ -719,14 +719,14 @@ public class BookServiceImpl implements BookService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Book> queryBookByUpdateTimeByPage(Date startDate, Date endDate, int page, int pageSize) {
|
||||
public List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit) {
|
||||
|
||||
PageHelper.startPage(page, pageSize);
|
||||
|
||||
return bookMapper.selectMany(select(book.allColumns())
|
||||
.from(book)
|
||||
.where(updateTime, isGreaterThanOrEqualTo(startDate))
|
||||
.and(updateTime, isLessThan(endDate))
|
||||
.where(updateTime, isGreaterThan(startDate))
|
||||
.orderBy(updateTime)
|
||||
.limit(limit)
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
Reference in New Issue
Block a user