]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-create.ts
Reduce video import TTL
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-create.ts
index 5197dac73455bef70c8d2cff984775c88404e713..c2160872f34bf2d12d6c6081dfb4d893671a3955 100644 (file)
@@ -9,7 +9,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoAbuseModel } from '../../../models/video/video-abuse'
 import { addVideoComment, resolveThread } from '../video-comments'
 import { getOrCreateVideoAndAccountAndChannel } from '../videos'
-import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
+import { forwardVideoRelatedActivity } from '../send/utils'
 import { Redis } from '../../redis'
 import { createCacheFile } from '../cache-file'
 
@@ -90,15 +90,12 @@ async function processCreateView (byActor: ActorModel, activity: ActivityCreate)
   }
   const { video } = await getOrCreateVideoAndAccountAndChannel(options)
 
-  const actorExists = await ActorModel.isActorUrlExist(view.actor)
-  if (actorExists === false) throw new Error('Unknown actor ' + view.actor)
-
   await Redis.Instance.addVideoView(video.id)
 
   if (video.isOwned()) {
     // Don't resend the activity to the sender
     const exceptions = [ byActor ]
-    await forwardActivity(activity, undefined, exceptions)
+    await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
   }
 }
 
@@ -107,12 +104,14 @@ async function processCacheFile (byActor: ActorModel, activity: ActivityCreate)
 
   const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object })
 
-  await createCacheFile(cacheFile, video, byActor)
+  await sequelizeTypescript.transaction(async t => {
+    return createCacheFile(cacheFile, video, byActor, t)
+  })
 
   if (video.isOwned()) {
     // Don't resend the activity to the sender
     const exceptions = [ byActor ]
-    await forwardActivity(activity, undefined, exceptions)
+    await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
   }
 }