Untitled
unknown
plain_text
2 years ago
4.6 kB
8
Indexable
for (List<Content> chunkContents : ZUtil.splitList(contents, 1000)) {
Map<Integer, ContentTag> existedContentTagMap = ContentTagDao.INST.getItems(0, Integer.MAX_VALUE, new SqlWhereClause.Builder()
.whereIn("contentId", chunkContents.stream().map(content -> content.contentId).toArray())
.build()).stream().collect(Collectors.toMap(e -> e.contentId, e -> e));
Map<Integer, CompleteContent> completeContentMap = CompleteContentDao.INST.getItems(0, Integer.MAX_VALUE, new SqlWhereClause.Builder()
.whereIn("contentId", chunkContents.stream().map(content -> content.contentId).toArray()).build())
.stream().collect(Collectors.toMap(e -> e.contentId, e -> e));
for (Content content : chunkContents) {
if (completeContentMap.containsKey(content.contentId)) {
if (!CommonUtils.isEmpty(completeContentMap.get(content.contentId).extraMap)) {
JsonObject extraMap = new JsonParser().parse(completeContentMap.get(content.contentId).extraMap).getAsJsonObject();
if (extraMap.has("tournamentTagId")) {
content2Tags.put(content.contentId, ConvertUtils.toInteger(extraMap.get("tournamentTagId")));
profiler.push(this.getClass(), "contentWithTournamentTagId");
profiler.pop(this.getClass(), "contentWithTournamentTagId");
}
}
}
}
List<ContentTag> contentTagsForInsert = new ArrayList<>();
List<ContentTag> contentTagsForUpdate = new ArrayList<>();
for (Content content : chunkContents) {
String tagIds = content2Tags.get(content.contentId).stream().sorted().map(String::valueOf).collect(Collectors.joining(","));
if (CommonUtils.isEmpty(tagIds)) {
tagIds = null;
}
LOG.info(CommonUtils.buildTabLog(content.contentId, genText(content.contentType, content.title, content.description, content.jsonBody),
content2Tags.get(content.contentId).stream().map(tagId -> String.join("-", String.valueOf(tagId), tagMap.get(tagId).name)).collect(Collectors.toSet())));
LOG.info("__________________________________________");
ContentTag existedContentTag = existedContentTagMap.get(content.contentId);
if (existedContentTag != null) {
if (!Objects.equals(existedContentTag.tagIds, tagIds)) {
existedContentTag.tagIds = tagIds;
contentTagsForUpdate.add(existedContentTag);
LOG.info(CommonUtils.buildTabLog("Update content tags", content.contentId, existedContentTag));
}
} else {
if (CommonUtils.isEmpty(tagIds)) {
continue;
}
ContentTag contentTag = new ContentTag();
contentTag.contentId = content.contentId;
// contentTag.modifiedDate = new Timestamp(System.currentTimeMillis());
contentTag.tagIds = tagIds;
contentTagsForInsert.add(contentTag);
LOG.info(CommonUtils.buildTabLog("Insert content tags", content.contentId, contentTag));
}
}
ContentTagDao.INST.update(contentTagsForUpdate);
ContentTagDao.INST.insert(contentTagsForInsert);
if (!CommonUtils.isEmpty(contentTagsForUpdate) || !CommonUtils.isEmpty(contentTagsForInsert)) {
LOG.info(CommonUtils.buildTabLog("Chunk", chunkId, "Inserted: " + contentTagsForInsert.size() + " Updated: " + contentTagsForUpdate.size()));
}
List<Integer> contentIds = Stream.concat(contentTagsForUpdate.stream().map(t -> t.contentId), contentTagsForInsert.stream().map(t -> t.contentId))
.collect(Collectors.toList());
if (!contentIds.isEmpty()) {
BScoreMWServiceClient.INST.notifyObject(TObjectType.CONTENT, contentIds);
LOG.info(CommonUtils.buildTabLog("Notify contents", contentIds));
}
chunkId += 1;
}Editor is loading...