import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments'
import { logger } from '../../helpers/logger'
import { doRequest } from '../../helpers/requests'
-import { ACTIVITY_PUB } from '../../initializers'
+import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers'
import { ActorModel } from '../../models/activitypub/actor'
import { VideoModel } from '../../models/video/video'
import { VideoCommentModel } from '../../models/video/video-comment'
import { getOrCreateActorAndServerAndModel } from './actor'
-import { getOrCreateAccountAndVideoAndChannel } from './videos'
+import { getOrCreateVideoAndAccountAndChannel } from './videos'
+import * as Bluebird from 'bluebird'
async function videoCommentActivityObjectToDBAttributes (video: VideoModel, actor: ActorModel, comment: VideoCommentObject) {
let originCommentId: number = null
}
}
-async function addVideoComments (instance: VideoModel, commentUrls: string[]) {
- for (const commentUrl of commentUrls) {
- await addVideoComment(instance, commentUrl)
- }
+async function addVideoComments (commentUrls: string[], instance: VideoModel) {
+ return Bluebird.map(commentUrls, commentUrl => {
+ return addVideoComment(instance, commentUrl)
+ }, { concurrency: CRAWL_REQUEST_CONCURRENCY })
}
async function addVideoComment (videoInstance: VideoModel, commentUrl: string) {
try {
// Maybe it's a reply to a video?
- const { video } = await getOrCreateAccountAndVideoAndChannel(url)
+ const { video } = await getOrCreateVideoAndAccountAndChannel(url)
if (comments.length !== 0) {
const firstReply = comments[ comments.length - 1 ]