aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-28 18:04:46 +0100
committerChocobozzz <me@florianbigard.com>2018-02-28 18:04:55 +0100
commit09cababd79f9d445aa027c93cdfe823745fa041a (patch)
treef781d6ba78b5c4ce7220dea55f13b21230f203d6 /server/models/activitypub
parent22b59e8099947605085cf65a440f07f37fce6b65 (diff)
downloadPeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.gz
PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.tar.zst
PeerTube-09cababd79f9d445aa027c93cdfe823745fa041a.zip
Add stats route
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts50
1 files changed, 22 insertions, 28 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index 8260904a1..3c11d1b67 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -8,6 +8,7 @@ import {
8import { FollowState } from '../../../shared/models/actors' 8import { FollowState } from '../../../shared/models/actors'
9import { AccountFollow } from '../../../shared/models/actors/follow.model' 9import { AccountFollow } from '../../../shared/models/actors/follow.model'
10import { logger } from '../../helpers/logger' 10import { logger } from '../../helpers/logger'
11import { getServerActor } from '../../helpers/utils'
11import { ACTOR_FOLLOW_SCORE } from '../../initializers' 12import { ACTOR_FOLLOW_SCORE } from '../../initializers'
12import { FOLLOW_STATES } from '../../initializers/constants' 13import { FOLLOW_STATES } from '../../initializers/constants'
13import { ServerModel } from '../server/server' 14import { ServerModel } from '../server/server'
@@ -182,34 +183,6 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
182 return ActorFollowModel.findOne(query) 183 return ActorFollowModel.findOne(query)
183 } 184 }
184 185
185 static loadByFollowerInbox (url: string, t?: Sequelize.Transaction) {
186 const query = {
187 where: {
188 state: 'accepted'
189 },
190 include: [
191 {
192 model: ActorModel,
193 required: true,
194 as: 'ActorFollower',
195 where: {
196 [Sequelize.Op.or]: [
197 {
198 inboxUrl: url
199 },
200 {
201 sharedInboxUrl: url
202 }
203 ]
204 }
205 }
206 ],
207 transaction: t
208 } as any // FIXME: typings does not work
209
210 return ActorFollowModel.findOne(query)
211 }
212
213 static listFollowingForApi (id: number, start: number, count: number, sort: string) { 186 static listFollowingForApi (id: number, start: number, count: number, sort: string) {
214 const query = { 187 const query = {
215 distinct: true, 188 distinct: true,
@@ -296,6 +269,27 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
296 return ActorFollowModel.createListAcceptedFollowForApiQuery('following', actorIds, t, start, count) 269 return ActorFollowModel.createListAcceptedFollowForApiQuery('following', actorIds, t, start, count)
297 } 270 }
298 271
272 static async getStats () {
273 const serverActor = await getServerActor()
274
275 const totalInstanceFollowing = await ActorFollowModel.count({
276 where: {
277 actorId: serverActor.id
278 }
279 })
280
281 const totalInstanceFollowers = await ActorFollowModel.count({
282 where: {
283 targetActorId: serverActor.id
284 }
285 })
286
287 return {
288 totalInstanceFollowing,
289 totalInstanceFollowers
290 }
291 }
292
299 private static async createListAcceptedFollowForApiQuery ( 293 private static async createListAcceptedFollowForApiQuery (
300 type: 'followers' | 'following', 294 type: 'followers' | 'following',
301 actorIds: number[], 295 actorIds: number[],