diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-13 14:27:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-13 14:27:40 +0200 |
commit | 90d4bb8125e80c8060416d4d135ddeaf0a622ede (patch) | |
tree | b3b7181329a08ecc930b54fe7b48095c4155393c /server/lib/activitypub | |
parent | 3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (diff) | |
download | PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.gz PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.zst PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.zip |
Refractor retry transaction function
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/actor.ts | 12 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-announce.ts | 13 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 37 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-delete.ts | 46 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 13 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 16 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 48 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 26 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 7 |
9 files changed, 30 insertions, 188 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index f27733418..9257d7d20 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -62,18 +62,10 @@ async function getOrCreateActorAndServerAndModel (activityActor: string | Activi | |||
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | const options = { | 65 | actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, result, ownerActor) |
66 | arguments: [ result, ownerActor ], | ||
67 | errorMessage: 'Cannot save actor and server with many retries.' | ||
68 | } | ||
69 | actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, options) | ||
70 | } | 66 | } |
71 | 67 | ||
72 | const options = { | 68 | return retryTransactionWrapper(refreshActorIfNeeded, actor) |
73 | arguments: [ actor ], | ||
74 | errorMessage: 'Cannot refresh actor if needed with many retries.' | ||
75 | } | ||
76 | return retryTransactionWrapper(refreshActorIfNeeded, options) | ||
77 | } | 69 | } |
78 | 70 | ||
79 | function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { | 71 | function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) { |
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 4e50da8d2..d8ca59425 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts | |||
@@ -11,7 +11,7 @@ import { getOrCreateAccountAndVideoAndChannel } from '../videos' | |||
11 | async function processAnnounceActivity (activity: ActivityAnnounce) { | 11 | async function processAnnounceActivity (activity: ActivityAnnounce) { |
12 | const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor) | 12 | const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor) |
13 | 13 | ||
14 | return processVideoShare(actorAnnouncer, activity) | 14 | return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity) |
15 | } | 15 | } |
16 | 16 | ||
17 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
@@ -22,16 +22,7 @@ export { | |||
22 | 22 | ||
23 | // --------------------------------------------------------------------------- | 23 | // --------------------------------------------------------------------------- |
24 | 24 | ||
25 | function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { | 25 | async function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { |
26 | const options = { | ||
27 | arguments: [ actorAnnouncer, activity ], | ||
28 | errorMessage: 'Cannot share the video activity with many retries.' | ||
29 | } | ||
30 | |||
31 | return retryTransactionWrapper(shareVideo, options) | ||
32 | } | ||
33 | |||
34 | async function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { | ||
35 | const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id | 26 | const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id |
36 | let video: VideoModel | 27 | let video: VideoModel |
37 | 28 | ||
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 38dacf772..6364bf135 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -21,13 +21,13 @@ async function processCreateActivity (activity: ActivityCreate) { | |||
21 | if (activityType === 'View') { | 21 | if (activityType === 'View') { |
22 | return processCreateView(actor, activity) | 22 | return processCreateView(actor, activity) |
23 | } else if (activityType === 'Dislike') { | 23 | } else if (activityType === 'Dislike') { |
24 | return processCreateDislike(actor, activity) | 24 | return retryTransactionWrapper(processCreateDislike, actor, activity) |
25 | } else if (activityType === 'Video') { | 25 | } else if (activityType === 'Video') { |
26 | return processCreateVideo(actor, activity) | 26 | return processCreateVideo(actor, activity) |
27 | } else if (activityType === 'Flag') { | 27 | } else if (activityType === 'Flag') { |
28 | return processCreateVideoAbuse(actor, activityObject as VideoAbuseObject) | 28 | return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject) |
29 | } else if (activityType === 'Note') { | 29 | } else if (activityType === 'Note') { |
30 | return processCreateVideoComment(actor, activity) | 30 | return retryTransactionWrapper(processCreateVideoComment, actor, activity) |
31 | } | 31 | } |
32 | 32 | ||
33 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) | 33 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) |
@@ -54,15 +54,6 @@ async function processCreateVideo ( | |||
54 | } | 54 | } |
55 | 55 | ||
56 | async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) { | 56 | async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) { |
57 | const options = { | ||
58 | arguments: [ byActor, activity ], | ||
59 | errorMessage: 'Cannot dislike the video with many retries.' | ||
60 | } | ||
61 | |||
62 | return retryTransactionWrapper(createVideoDislike, options) | ||
63 | } | ||
64 | |||
65 | async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate) { | ||
66 | const dislike = activity.object as DislikeObject | 57 | const dislike = activity.object as DislikeObject |
67 | const byAccount = byActor.Account | 58 | const byAccount = byActor.Account |
68 | 59 | ||
@@ -109,16 +100,7 @@ async function processCreateView (byActor: ActorModel, activity: ActivityCreate) | |||
109 | } | 100 | } |
110 | } | 101 | } |
111 | 102 | ||
112 | function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { | 103 | async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { |
113 | const options = { | ||
114 | arguments: [ actor, videoAbuseToCreateData ], | ||
115 | errorMessage: 'Cannot insert the remote video abuse with many retries.' | ||
116 | } | ||
117 | |||
118 | return retryTransactionWrapper(addRemoteVideoAbuse, options) | ||
119 | } | ||
120 | |||
121 | async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) { | ||
122 | logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) | 104 | logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) |
123 | 105 | ||
124 | const account = actor.Account | 106 | const account = actor.Account |
@@ -139,16 +121,7 @@ async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: V | |||
139 | }) | 121 | }) |
140 | } | 122 | } |
141 | 123 | ||
142 | function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) { | 124 | async function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) { |
143 | const options = { | ||
144 | arguments: [ byActor, activity ], | ||
145 | errorMessage: 'Cannot create video comment with many retries.' | ||
146 | } | ||
147 | |||
148 | return retryTransactionWrapper(createVideoComment, options) | ||
149 | } | ||
150 | |||
151 | async function createVideoComment (byActor: ActorModel, activity: ActivityCreate) { | ||
152 | const comment = activity.object as VideoCommentObject | 125 | const comment = activity.object as VideoCommentObject |
153 | const byAccount = byActor.Account | 126 | const byAccount = byActor.Account |
154 | 127 | ||
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 8310b70f0..ff0caa343 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts | |||
@@ -21,12 +21,12 @@ async function processDeleteActivity (activity: ActivityDelete) { | |||
21 | if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') | 21 | if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') |
22 | 22 | ||
23 | actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel | 23 | actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel |
24 | return processDeleteAccount(actor.Account) | 24 | return retryTransactionWrapper(processDeleteAccount, actor.Account) |
25 | } else if (actor.type === 'Group') { | 25 | } else if (actor.type === 'Group') { |
26 | if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.') | 26 | if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.') |
27 | 27 | ||
28 | actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel | 28 | actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel |
29 | return processDeleteVideoChannel(actor.VideoChannel) | 29 | return retryTransactionWrapper(processDeleteVideoChannel, actor.VideoChannel) |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
@@ -34,14 +34,14 @@ async function processDeleteActivity (activity: ActivityDelete) { | |||
34 | { | 34 | { |
35 | const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) | 35 | const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) |
36 | if (videoCommentInstance) { | 36 | if (videoCommentInstance) { |
37 | return processDeleteVideoComment(actor, videoCommentInstance, activity) | 37 | return retryTransactionWrapper(processDeleteVideoComment, actor, videoCommentInstance, activity) |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | { | 41 | { |
42 | const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl) | 42 | const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl) |
43 | if (videoInstance) { | 43 | if (videoInstance) { |
44 | return processDeleteVideo(actor, videoInstance) | 44 | return retryTransactionWrapper(processDeleteVideo, actor, videoInstance) |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
@@ -57,15 +57,6 @@ export { | |||
57 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
58 | 58 | ||
59 | async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) { | 59 | async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) { |
60 | const options = { | ||
61 | arguments: [ actor, videoToDelete ], | ||
62 | errorMessage: 'Cannot remove the remote video with many retries.' | ||
63 | } | ||
64 | |||
65 | await retryTransactionWrapper(deleteRemoteVideo, options) | ||
66 | } | ||
67 | |||
68 | async function deleteRemoteVideo (actor: ActorModel, videoToDelete: VideoModel) { | ||
69 | logger.debug('Removing remote video "%s".', videoToDelete.uuid) | 60 | logger.debug('Removing remote video "%s".', videoToDelete.uuid) |
70 | 61 | ||
71 | await sequelizeTypescript.transaction(async t => { | 62 | await sequelizeTypescript.transaction(async t => { |
@@ -80,15 +71,6 @@ async function deleteRemoteVideo (actor: ActorModel, videoToDelete: VideoModel) | |||
80 | } | 71 | } |
81 | 72 | ||
82 | async function processDeleteAccount (accountToRemove: AccountModel) { | 73 | async function processDeleteAccount (accountToRemove: AccountModel) { |
83 | const options = { | ||
84 | arguments: [ accountToRemove ], | ||
85 | errorMessage: 'Cannot remove the remote account with many retries.' | ||
86 | } | ||
87 | |||
88 | await retryTransactionWrapper(deleteRemoteAccount, options) | ||
89 | } | ||
90 | |||
91 | async function deleteRemoteAccount (accountToRemove: AccountModel) { | ||
92 | logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid) | 74 | logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid) |
93 | 75 | ||
94 | await sequelizeTypescript.transaction(async t => { | 76 | await sequelizeTypescript.transaction(async t => { |
@@ -99,15 +81,6 @@ async function deleteRemoteAccount (accountToRemove: AccountModel) { | |||
99 | } | 81 | } |
100 | 82 | ||
101 | async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) { | 83 | async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) { |
102 | const options = { | ||
103 | arguments: [ videoChannelToRemove ], | ||
104 | errorMessage: 'Cannot remove the remote video channel with many retries.' | ||
105 | } | ||
106 | |||
107 | await retryTransactionWrapper(deleteRemoteVideoChannel, options) | ||
108 | } | ||
109 | |||
110 | async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel) { | ||
111 | logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.uuid) | 84 | logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.uuid) |
112 | 85 | ||
113 | await sequelizeTypescript.transaction(async t => { | 86 | await sequelizeTypescript.transaction(async t => { |
@@ -117,16 +90,7 @@ async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel | |||
117 | logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid) | 90 | logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid) |
118 | } | 91 | } |
119 | 92 | ||
120 | async function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) { | 93 | function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) { |
121 | const options = { | ||
122 | arguments: [ byActor, videoComment, activity ], | ||
123 | errorMessage: 'Cannot remove the remote video comment with many retries.' | ||
124 | } | ||
125 | |||
126 | await retryTransactionWrapper(deleteRemoteVideoComment, options) | ||
127 | } | ||
128 | |||
129 | function deleteRemoteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) { | ||
130 | logger.debug('Removing remote video comment "%s".', videoComment.url) | 94 | logger.debug('Removing remote video comment "%s".', videoComment.url) |
131 | 95 | ||
132 | return sequelizeTypescript.transaction(async t => { | 96 | return sequelizeTypescript.transaction(async t => { |
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index dc1d542b5..f34fd66cc 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -11,7 +11,7 @@ async function processFollowActivity (activity: ActivityFollow) { | |||
11 | const activityObject = activity.object | 11 | const activityObject = activity.object |
12 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | 12 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) |
13 | 13 | ||
14 | return processFollow(actor, activityObject) | 14 | return retryTransactionWrapper(processFollow, actor, activityObject) |
15 | } | 15 | } |
16 | 16 | ||
17 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
@@ -22,16 +22,7 @@ export { | |||
22 | 22 | ||
23 | // --------------------------------------------------------------------------- | 23 | // --------------------------------------------------------------------------- |
24 | 24 | ||
25 | function processFollow (actor: ActorModel, targetActorURL: string) { | 25 | async function processFollow (actor: ActorModel, targetActorURL: string) { |
26 | const options = { | ||
27 | arguments: [ actor, targetActorURL ], | ||
28 | errorMessage: 'Cannot follow with many retries.' | ||
29 | } | ||
30 | |||
31 | return retryTransactionWrapper(follow, options) | ||
32 | } | ||
33 | |||
34 | async function follow (actor: ActorModel, targetActorURL: string) { | ||
35 | await sequelizeTypescript.transaction(async t => { | 26 | await sequelizeTypescript.transaction(async t => { |
36 | const targetActor = await ActorModel.loadByUrl(targetActorURL, t) | 27 | const targetActor = await ActorModel.loadByUrl(targetActorURL, t) |
37 | 28 | ||
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index f1642f038..d0865b78c 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -4,14 +4,13 @@ import { sequelizeTypescript } from '../../../initializers' | |||
4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { getOrCreateActorAndServerAndModel } from '../actor' | 6 | import { getOrCreateActorAndServerAndModel } from '../actor' |
7 | import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' | 7 | import { forwardVideoRelatedActivity } from '../send/utils' |
8 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 8 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
9 | import { getActorsInvolvedInVideo } from '../audience' | ||
10 | 9 | ||
11 | async function processLikeActivity (activity: ActivityLike) { | 10 | async function processLikeActivity (activity: ActivityLike) { |
12 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | 11 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) |
13 | 12 | ||
14 | return processLikeVideo(actor, activity) | 13 | return retryTransactionWrapper(processLikeVideo, actor, activity) |
15 | } | 14 | } |
16 | 15 | ||
17 | // --------------------------------------------------------------------------- | 16 | // --------------------------------------------------------------------------- |
@@ -22,16 +21,7 @@ export { | |||
22 | 21 | ||
23 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
24 | 23 | ||
25 | async function processLikeVideo (actor: ActorModel, activity: ActivityLike) { | 24 | async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) { |
26 | const options = { | ||
27 | arguments: [ actor, activity ], | ||
28 | errorMessage: 'Cannot like the video with many retries.' | ||
29 | } | ||
30 | |||
31 | return retryTransactionWrapper(createVideoLike, options) | ||
32 | } | ||
33 | |||
34 | async function createVideoLike (byActor: ActorModel, activity: ActivityLike) { | ||
35 | const videoUrl = activity.object | 25 | const videoUrl = activity.object |
36 | 26 | ||
37 | const byAccount = byActor.Account | 27 | const byAccount = byActor.Account |
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 37db58e1a..b6de107ad 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -18,13 +18,13 @@ async function processUndoActivity (activity: ActivityUndo) { | |||
18 | const actorUrl = getActorUrl(activity.actor) | 18 | const actorUrl = getActorUrl(activity.actor) |
19 | 19 | ||
20 | if (activityToUndo.type === 'Like') { | 20 | if (activityToUndo.type === 'Like') { |
21 | return processUndoLike(actorUrl, activity) | 21 | return retryTransactionWrapper(processUndoLike, actorUrl, activity) |
22 | } else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') { | 22 | } else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') { |
23 | return processUndoDislike(actorUrl, activity) | 23 | return retryTransactionWrapper(processUndoDislike, actorUrl, activity) |
24 | } else if (activityToUndo.type === 'Follow') { | 24 | } else if (activityToUndo.type === 'Follow') { |
25 | return processUndoFollow(actorUrl, activityToUndo) | 25 | return retryTransactionWrapper(processUndoFollow, actorUrl, activityToUndo) |
26 | } else if (activityToUndo.type === 'Announce') { | 26 | } else if (activityToUndo.type === 'Announce') { |
27 | return processUndoAnnounce(actorUrl, activityToUndo) | 27 | return retryTransactionWrapper(processUndoAnnounce, actorUrl, activityToUndo) |
28 | } | 28 | } |
29 | 29 | ||
30 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) | 30 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) |
@@ -40,16 +40,7 @@ export { | |||
40 | 40 | ||
41 | // --------------------------------------------------------------------------- | 41 | // --------------------------------------------------------------------------- |
42 | 42 | ||
43 | function processUndoLike (actorUrl: string, activity: ActivityUndo) { | 43 | async function processUndoLike (actorUrl: string, activity: ActivityUndo) { |
44 | const options = { | ||
45 | arguments: [ actorUrl, activity ], | ||
46 | errorMessage: 'Cannot undo like with many retries.' | ||
47 | } | ||
48 | |||
49 | return retryTransactionWrapper(undoLike, options) | ||
50 | } | ||
51 | |||
52 | async function undoLike (actorUrl: string, activity: ActivityUndo) { | ||
53 | const likeActivity = activity.object as ActivityLike | 44 | const likeActivity = activity.object as ActivityLike |
54 | 45 | ||
55 | const { video } = await getOrCreateAccountAndVideoAndChannel(likeActivity.object) | 46 | const { video } = await getOrCreateAccountAndVideoAndChannel(likeActivity.object) |
@@ -73,16 +64,7 @@ async function undoLike (actorUrl: string, activity: ActivityUndo) { | |||
73 | }) | 64 | }) |
74 | } | 65 | } |
75 | 66 | ||
76 | function processUndoDislike (actorUrl: string, activity: ActivityUndo) { | 67 | async function processUndoDislike (actorUrl: string, activity: ActivityUndo) { |
77 | const options = { | ||
78 | arguments: [ actorUrl, activity ], | ||
79 | errorMessage: 'Cannot undo dislike with many retries.' | ||
80 | } | ||
81 | |||
82 | return retryTransactionWrapper(undoDislike, options) | ||
83 | } | ||
84 | |||
85 | async function undoDislike (actorUrl: string, activity: ActivityUndo) { | ||
86 | const dislike = activity.object.object as DislikeObject | 68 | const dislike = activity.object.object as DislikeObject |
87 | 69 | ||
88 | const { video } = await getOrCreateAccountAndVideoAndChannel(dislike.object) | 70 | const { video } = await getOrCreateAccountAndVideoAndChannel(dislike.object) |
@@ -107,15 +89,6 @@ async function undoDislike (actorUrl: string, activity: ActivityUndo) { | |||
107 | } | 89 | } |
108 | 90 | ||
109 | function processUndoFollow (actorUrl: string, followActivity: ActivityFollow) { | 91 | function processUndoFollow (actorUrl: string, followActivity: ActivityFollow) { |
110 | const options = { | ||
111 | arguments: [ actorUrl, followActivity ], | ||
112 | errorMessage: 'Cannot undo follow with many retries.' | ||
113 | } | ||
114 | |||
115 | return retryTransactionWrapper(undoFollow, options) | ||
116 | } | ||
117 | |||
118 | function undoFollow (actorUrl: string, followActivity: ActivityFollow) { | ||
119 | return sequelizeTypescript.transaction(async t => { | 92 | return sequelizeTypescript.transaction(async t => { |
120 | const follower = await ActorModel.loadByUrl(actorUrl, t) | 93 | const follower = await ActorModel.loadByUrl(actorUrl, t) |
121 | const following = await ActorModel.loadByUrl(followActivity.object, t) | 94 | const following = await ActorModel.loadByUrl(followActivity.object, t) |
@@ -130,15 +103,6 @@ function undoFollow (actorUrl: string, followActivity: ActivityFollow) { | |||
130 | } | 103 | } |
131 | 104 | ||
132 | function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { | 105 | function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { |
133 | const options = { | ||
134 | arguments: [ actorUrl, announceActivity ], | ||
135 | errorMessage: 'Cannot undo announce with many retries.' | ||
136 | } | ||
137 | |||
138 | return retryTransactionWrapper(undoAnnounce, options) | ||
139 | } | ||
140 | |||
141 | function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { | ||
142 | return sequelizeTypescript.transaction(async t => { | 106 | return sequelizeTypescript.transaction(async t => { |
143 | const byAccount = await AccountModel.loadByUrl(actorUrl, t) | 107 | const byAccount = await AccountModel.loadByUrl(actorUrl, t) |
144 | if (!byAccount) throw new Error('Unknown account ' + actorUrl) | 108 | if (!byAccount) throw new Error('Unknown account ' + actorUrl) |
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 1ebda46d3..73db461c3 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -25,9 +25,9 @@ async function processUpdateActivity (activity: ActivityUpdate) { | |||
25 | const objectType = activity.object.type | 25 | const objectType = activity.object.type |
26 | 26 | ||
27 | if (objectType === 'Video') { | 27 | if (objectType === 'Video') { |
28 | return processUpdateVideo(actor, activity) | 28 | return retryTransactionWrapper(processUpdateVideo, actor, activity) |
29 | } else if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') { | 29 | } else if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') { |
30 | return processUpdateActor(actor, activity) | 30 | return retryTransactionWrapper(processUpdateActor, actor, activity) |
31 | } | 31 | } |
32 | 32 | ||
33 | return undefined | 33 | return undefined |
@@ -41,16 +41,7 @@ export { | |||
41 | 41 | ||
42 | // --------------------------------------------------------------------------- | 42 | // --------------------------------------------------------------------------- |
43 | 43 | ||
44 | function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) { | 44 | async function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) { |
45 | const options = { | ||
46 | arguments: [ actor, activity ], | ||
47 | errorMessage: 'Cannot update the remote video with many retries' | ||
48 | } | ||
49 | |||
50 | return retryTransactionWrapper(updateRemoteVideo, options) | ||
51 | } | ||
52 | |||
53 | async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { | ||
54 | const videoObject = activity.object as VideoTorrentObject | 45 | const videoObject = activity.object as VideoTorrentObject |
55 | 46 | ||
56 | if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { | 47 | if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { |
@@ -136,16 +127,7 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) { | |||
136 | } | 127 | } |
137 | } | 128 | } |
138 | 129 | ||
139 | function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { | 130 | async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { |
140 | const options = { | ||
141 | arguments: [ actor, activity ], | ||
142 | errorMessage: 'Cannot update the remote actor with many retries' | ||
143 | } | ||
144 | |||
145 | return retryTransactionWrapper(updateRemoteActor, options) | ||
146 | } | ||
147 | |||
148 | async function updateRemoteActor (actor: ActorModel, activity: ActivityUpdate) { | ||
149 | const actorAttributesToUpdate = activity.object as ActivityPubActor | 131 | const actorAttributesToUpdate = activity.object as ActivityPubActor |
150 | 132 | ||
151 | logger.debug('Updating remote account "%s".', actorAttributesToUpdate.uuid) | 133 | logger.debug('Updating remote account "%s".', actorAttributesToUpdate.uuid) |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 7ec8ca193..a16828fda 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -228,12 +228,7 @@ async function getOrCreateAccountAndVideoAndChannel (videoObject: VideoTorrentOb | |||
228 | 228 | ||
229 | const channelActor = await getOrCreateVideoChannel(videoObject) | 229 | const channelActor = await getOrCreateVideoChannel(videoObject) |
230 | 230 | ||
231 | const options = { | 231 | const video = await retryTransactionWrapper(getOrCreateVideo, videoObject, channelActor) |
232 | arguments: [ videoObject, channelActor ], | ||
233 | errorMessage: 'Cannot insert the remote video with many retries.' | ||
234 | } | ||
235 | |||
236 | const video = await retryTransactionWrapper(getOrCreateVideo, options) | ||
237 | 232 | ||
238 | // Process outside the transaction because we could fetch remote data | 233 | // Process outside the transaction because we could fetch remote data |
239 | logger.info('Adding likes of video %s.', video.uuid) | 234 | logger.info('Adding likes of video %s.', video.uuid) |