aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-25 16:21:16 +0200
committerChocobozzz <me@florianbigard.com>2018-05-25 16:21:16 +0200
commit8fffe21a7bc96d08b229293d66ddba576e609790 (patch)
tree5ebd5f5198a59084c5338ce197d7e836b39200a4 /server/models/video/video.ts
parente251f170b00b2014ac4e823113c6ff40e3fb1471 (diff)
downloadPeerTube-8fffe21a7bc96d08b229293d66ddba576e609790.tar.gz
PeerTube-8fffe21a7bc96d08b229293d66ddba576e609790.tar.zst
PeerTube-8fffe21a7bc96d08b229293d66ddba576e609790.zip
Refractor and optimize AP collections
Only display urls in general object, and paginate video comments, shares, likes and dislikes
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts128
1 files changed, 5 insertions, 123 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 012a758ee..f4689fe12 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -29,7 +29,7 @@ import { VideoPrivacy, VideoResolution } from '../../../shared'
29import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 29import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
30import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' 30import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
31import { VideoFilter } from '../../../shared/models/videos/video-query.type' 31import { VideoFilter } from '../../../shared/models/videos/video-query.type'
32import { activityPubCollection } from '../../helpers/activitypub' 32import { activityPubCollectionPagination } from '../../helpers/activitypub'
33import { 33import {
34 createTorrentPromise, 34 createTorrentPromise,
35 peertubeTruncate, 35 peertubeTruncate,
@@ -602,18 +602,6 @@ export class VideoModel extends Model<VideoModel> {
602 attributes: [ 'id', 'url' ], 602 attributes: [ 'id', 'url' ],
603 model: VideoShareModel.unscoped(), 603 model: VideoShareModel.unscoped(),
604 required: false, 604 required: false,
605 where: {
606 [Sequelize.Op.and]: [
607 {
608 id: {
609 [Sequelize.Op.not]: null
610 }
611 },
612 {
613 actorId
614 }
615 ]
616 },
617 include: [ 605 include: [
618 { 606 {
619 attributes: [ 'id', 'url' ], 607 attributes: [ 'id', 'url' ],
@@ -644,35 +632,6 @@ export class VideoModel extends Model<VideoModel> {
644 } 632 }
645 ] 633 ]
646 }, 634 },
647 {
648 attributes: [ 'type' ],
649 model: AccountVideoRateModel,
650 required: false,
651 include: [
652 {
653 attributes: [ 'id' ],
654 model: AccountModel.unscoped(),
655 include: [
656 {
657 attributes: [ 'url' ],
658 model: ActorModel.unscoped(),
659 include: [
660 {
661 attributes: [ 'host' ],
662 model: ServerModel,
663 required: false
664 }
665 ]
666 }
667 ]
668 }
669 ]
670 },
671 {
672 attributes: [ 'url' ],
673 model: VideoCommentModel,
674 required: false
675 },
676 VideoFileModel, 635 VideoFileModel,
677 TagModel 636 TagModel
678 ] 637 ]
@@ -897,26 +856,6 @@ export class VideoModel extends Model<VideoModel> {
897 .findOne(options) 856 .findOne(options)
898 } 857 }
899 858
900 static loadAndPopulateAll (id: number) {
901 const options = {
902 order: [ [ 'Tags', 'name', 'ASC' ] ],
903 where: {
904 id
905 }
906 }
907
908 return VideoModel
909 .scope([
910 ScopeNames.WITH_RATES,
911 ScopeNames.WITH_SHARES,
912 ScopeNames.WITH_TAGS,
913 ScopeNames.WITH_FILES,
914 ScopeNames.WITH_ACCOUNT_DETAILS,
915 ScopeNames.WITH_COMMENTS
916 ])
917 .findOne(options)
918 }
919
920 static async getStats () { 859 static async getStats () {
921 const totalLocalVideos = await VideoModel.count({ 860 const totalLocalVideos = await VideoModel.count({
922 where: { 861 where: {
@@ -1203,25 +1142,6 @@ export class VideoModel extends Model<VideoModel> {
1203 } 1142 }
1204 } 1143 }
1205 1144
1206 let likesObject
1207 let dislikesObject
1208
1209 if (Array.isArray(this.AccountVideoRates)) {
1210 const res = this.toRatesActivityPubObjects()
1211 likesObject = res.likesObject
1212 dislikesObject = res.dislikesObject
1213 }
1214
1215 let sharesObject
1216 if (Array.isArray(this.VideoShares)) {
1217 sharesObject = this.toAnnouncesActivityPubObject()
1218 }
1219
1220 let commentsObject
1221 if (Array.isArray(this.VideoComments)) {
1222 commentsObject = this.toCommentsActivityPubObject()
1223 }
1224
1225 const url = [] 1145 const url = []
1226 for (const file of this.VideoFiles) { 1146 for (const file of this.VideoFiles) {
1227 url.push({ 1147 url.push({
@@ -1280,10 +1200,10 @@ export class VideoModel extends Model<VideoModel> {
1280 height: THUMBNAILS_SIZE.height 1200 height: THUMBNAILS_SIZE.height
1281 }, 1201 },
1282 url, 1202 url,
1283 likes: likesObject, 1203 likes: getVideoLikesActivityPubUrl(this),
1284 dislikes: dislikesObject, 1204 dislikes: getVideoDislikesActivityPubUrl(this),
1285 shares: sharesObject, 1205 shares: getVideoSharesActivityPubUrl(this),
1286 comments: commentsObject, 1206 comments: getVideoCommentsActivityPubUrl(this),
1287 attributedTo: [ 1207 attributedTo: [
1288 { 1208 {
1289 type: 'Person', 1209 type: 'Person',
@@ -1297,44 +1217,6 @@ export class VideoModel extends Model<VideoModel> {
1297 } 1217 }
1298 } 1218 }
1299 1219
1300 toAnnouncesActivityPubObject () {
1301 const shares: string[] = []
1302
1303 for (const videoShare of this.VideoShares) {
1304 shares.push(videoShare.url)
1305 }
1306
1307 return activityPubCollection(getVideoSharesActivityPubUrl(this), shares)
1308 }
1309
1310 toCommentsActivityPubObject () {
1311 const comments: string[] = []
1312
1313 for (const videoComment of this.VideoComments) {
1314 comments.push(videoComment.url)
1315 }
1316
1317 return activityPubCollection(getVideoCommentsActivityPubUrl(this), comments)
1318 }
1319
1320 toRatesActivityPubObjects () {
1321 const likes: string[] = []
1322 const dislikes: string[] = []
1323
1324 for (const rate of this.AccountVideoRates) {
1325 if (rate.type === 'like') {
1326 likes.push(rate.Account.Actor.url)
1327 } else if (rate.type === 'dislike') {
1328 dislikes.push(rate.Account.Actor.url)
1329 }
1330 }
1331
1332 const likesObject = activityPubCollection(getVideoLikesActivityPubUrl(this), likes)
1333 const dislikesObject = activityPubCollection(getVideoDislikesActivityPubUrl(this), dislikes)
1334
1335 return { likesObject, dislikesObject }
1336 }
1337
1338 getTruncatedDescription () { 1220 getTruncatedDescription () {
1339 if (!this.description) return null 1221 if (!this.description) return null
1340 1222