mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-22 08:46:54 -06:00
Avoid making retried requests to dead followers
This commit is contained in:
parent
9a8cbd8278
commit
6502c3d43e
@ -81,7 +81,6 @@ async function resolveThread (url: string, comments: VideoCommentModel[] = []) {
|
||||
// Speed up things and resolve directly the thread
|
||||
if (commentFromDatabase.InReplyToVideoComment) {
|
||||
const data = await VideoCommentModel.listThreadParentComments(commentFromDatabase, undefined, 'DESC')
|
||||
console.log(data)
|
||||
|
||||
parentComments = parentComments.concat(data)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import { logger } from '../../../helpers/logger'
|
||||
import { getServerActor } from '../../../helpers/utils'
|
||||
import { ACTIVITY_PUB } from '../../../initializers'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
import { JobHandler, JobScheduler } from '../job-scheduler'
|
||||
|
||||
import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler'
|
||||
@ -35,6 +36,12 @@ async function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPaylo
|
||||
if (attemptNumber < ACTIVITY_PUB.MAX_HTTP_ATTEMPT) {
|
||||
logger.debug('Retrying request to %s (attempt %d/%d).', uri, attemptNumber, ACTIVITY_PUB.MAX_HTTP_ATTEMPT, err)
|
||||
|
||||
const actor = await ActorFollowModel.loadByFollowerInbox(uri, undefined)
|
||||
if (!actor) {
|
||||
logger.debug('Actor %s is not a follower, do not retry the request.', uri)
|
||||
return false
|
||||
}
|
||||
|
||||
const newPayload = Object.assign(payload, {
|
||||
uris: [ uri ],
|
||||
attemptNumber
|
||||
|
@ -6,10 +6,11 @@ import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRe
|
||||
async function process (payload: ActivityPubHttpPayload, jobId: number) {
|
||||
logger.info('Processing ActivityPub unicast in job %d.', jobId)
|
||||
|
||||
const uri = payload.uris[0]
|
||||
|
||||
const body = await computeBody(payload)
|
||||
const httpSignatureOptions = await buildSignedRequestOptions(payload)
|
||||
|
||||
const uri = payload.uris[0]
|
||||
const options = {
|
||||
method: 'POST',
|
||||
uri,
|
||||
|
@ -35,7 +35,6 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
|
||||
function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
const accepted = req.accepts(ACCEPT_HEADERS)
|
||||
console.log(accepted)
|
||||
if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) {
|
||||
return next()
|
||||
}
|
||||
|
@ -163,6 +163,34 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
|
||||
return ActorFollowModel.findOne(query)
|
||||
}
|
||||
|
||||
static loadByFollowerInbox (url: string, t?: Sequelize.Transaction) {
|
||||
const query = {
|
||||
where: {
|
||||
state: 'accepted'
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: ActorModel,
|
||||
required: true,
|
||||
as: 'ActorFollower',
|
||||
where: {
|
||||
[Sequelize.Op.or]: [
|
||||
{
|
||||
inboxUrl: url
|
||||
},
|
||||
{
|
||||
sharedInboxUrl: url
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
transaction: t
|
||||
} as any // FIXME: typings does not work
|
||||
|
||||
return ActorFollowModel.findOne(query)
|
||||
}
|
||||
|
||||
static listFollowingForApi (id: number, start: number, count: number, sort: string) {
|
||||
const query = {
|
||||
distinct: true,
|
||||
|
@ -68,6 +68,9 @@ enum ScopeNames {
|
||||
{
|
||||
fields: [ 'preferredUsername', 'serverId' ],
|
||||
unique: true
|
||||
},
|
||||
{
|
||||
fields: [ 'inboxUrl', 'sharedInboxUrl' ]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
@ -113,6 +113,10 @@ describe('Test handle downs', function () {
|
||||
videos.push(resVideo.body.video)
|
||||
}
|
||||
|
||||
await wait(2000)
|
||||
|
||||
await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
|
||||
|
||||
// Add comments to video 2
|
||||
{
|
||||
const text = 'thread 1'
|
||||
|
Loading…
Reference in New Issue
Block a user