}
@Override
public FeedResult getFeeds(Long ownerId, Integer current, Integer level) {
FeedResult result = new FeedResult();
List<DBObject> resultData = new ArrayList<DBObject>();
// 当返回推信数目小于MIN_PAGE_SIZE则会自动也去找下一级的personalFeed
while (resultData.size() < MIN_PAGE_SIZE) {
// 当找完了所有的personalFeed后,break;MAX_FEED_LEVEL表示最大的personalFeed的index;level
// >= MAX_FEED_LEVEL意味找完了所有的personalFeed
if (level > MAX_FEED_LEVEL) {
break;
}
DBCursor cursor = personalFeedDao.queryFeeds(ownerId, current, level);
// while(cursor.hasNext()){
// resultData.add(cursor.next());
// }
List<DBObject> feeds = cursor.toArray();
resultData.addAll(feeds);
// 当返回推信数目小于MIN_PAGE_SIZE,则将currentPage置为0,并会自动也去找下一级的personalFeed
if (resultData.size() < MIN_PAGE_SIZE) {
current = 0;
level = level + 1;
} else {
current = feeds.size();
}
}
result.setCurrent(current);
result.setData(resultData);
result.setLevel(level);
return result;
}