mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Update follower/following counts
This commit is contained in:
parent
6502c3d43e
commit
32b2b43c06
8 changed files with 108 additions and 1 deletions
|
@ -2,6 +2,7 @@ import * as Bluebird from 'bluebird'
|
|||
import { values } from 'lodash'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import {
|
||||
AfterCreate, AfterDestroy, AfterUpdate,
|
||||
AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, IsInt, Max, Model, Table,
|
||||
UpdatedAt
|
||||
} from 'sequelize-typescript'
|
||||
|
@ -79,6 +80,25 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
|
|||
})
|
||||
ActorFollowing: ActorModel
|
||||
|
||||
@AfterCreate
|
||||
@AfterUpdate
|
||||
static incrementFollowerAndFollowingCount (instance: ActorFollowModel) {
|
||||
if (instance.state !== 'accepted') return
|
||||
|
||||
return Promise.all([
|
||||
ActorModel.incrementFollows(instance.actorId, 'followingCount', 1),
|
||||
ActorModel.incrementFollows(instance.targetActorId, 'followersCount', 1)
|
||||
])
|
||||
}
|
||||
|
||||
@AfterDestroy
|
||||
static decrementFollowerAndFollowingCount (instance: ActorFollowModel) {
|
||||
return Promise.all([
|
||||
ActorModel.incrementFollows(instance.actorId, 'followingCount',-1),
|
||||
ActorModel.incrementFollows(instance.targetActorId, 'followersCount', -1)
|
||||
])
|
||||
}
|
||||
|
||||
// Remove actor follows with a score of 0 (too many requests where they were unreachable)
|
||||
static async removeBadActorFollows () {
|
||||
const actorFollows = await ActorFollowModel.listBadActorFollows()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue