aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/user.ts9
-rw-r--r--server/models/activitypub/actor-follow.ts50
-rw-r--r--server/models/video/video-comment.ts26
-rw-r--r--server/models/video/video.ts23
4 files changed, 80 insertions, 28 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 74cf0f4a8..afa9d7be0 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -13,6 +13,7 @@ import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
13import { OAuthTokenModel } from '../oauth/oauth-token' 13import { OAuthTokenModel } from '../oauth/oauth-token'
14import { getSort, throwIfNotValid } from '../utils' 14import { getSort, throwIfNotValid } from '../utils'
15import { VideoChannelModel } from '../video/video-channel' 15import { VideoChannelModel } from '../video/video-channel'
16import { VideoCommentModel } from '../video/video-comment'
16import { AccountModel } from './account' 17import { AccountModel } from './account'
17 18
18@DefaultScope({ 19@DefaultScope({
@@ -226,6 +227,14 @@ export class UserModel extends Model<UserModel> {
226 }) 227 })
227 } 228 }
228 229
230 static async getStats () {
231 const totalUsers = await UserModel.count()
232
233 return {
234 totalUsers
235 }
236 }
237
229 hasRight (right: UserRight) { 238 hasRight (right: UserRight) {
230 return hasUserRight(this.role, right) 239 return hasUserRight(this.role, right)
231 } 240 }
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[],
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 47e3211a3..bf8da924d 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -326,6 +326,32 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
326 .findAll(query) 326 .findAll(query)
327 } 327 }
328 328
329 static async getStats () {
330 const totalLocalVideoComments = await VideoCommentModel.count({
331 include: [
332 {
333 model: AccountModel,
334 required: true,
335 include: [
336 {
337 model: ActorModel,
338 required: true,
339 where: {
340 serverId: null
341 }
342 }
343 ]
344 }
345 ]
346 })
347 const totalVideoComments = await VideoCommentModel.count()
348
349 return {
350 totalLocalVideoComments,
351 totalVideoComments
352 }
353 }
354
329 getThreadId (): number { 355 getThreadId (): number {
330 return this.originCommentId || this.id 356 return this.originCommentId || this.id
331 } 357 }
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 80ca513bf..f6a21814c 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -761,6 +761,29 @@ export class VideoModel extends Model<VideoModel> {
761 .findOne(options) 761 .findOne(options)
762 } 762 }
763 763
764 static async getStats () {
765 const totalLocalVideos = await VideoModel.count({
766 where: {
767 remote: false
768 }
769 })
770 const totalVideos = await VideoModel.count()
771
772 let totalLocalVideoViews = await VideoModel.sum('views', {
773 where: {
774 remote: false
775 }
776 })
777 // Sequelize could return null...
778 if (!totalLocalVideoViews) totalLocalVideoViews = 0
779
780 return {
781 totalLocalVideos,
782 totalLocalVideoViews,
783 totalVideos
784 }
785 }
786
764 getOriginalFile () { 787 getOriginalFile () {
765 if (Array.isArray(this.VideoFiles) === false) return undefined 788 if (Array.isArray(this.VideoFiles) === false) return undefined
766 789