diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-22 11:27:40 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | c46edbc2f6ca310b2f0331f979ac6caf27f6eb92 (patch) | |
tree | 073e32adb1bf93a597a269432e33a8f28365deb5 /server/models | |
parent | c986175d68a18e96fbd41537a05c7796a2c64f38 (diff) | |
download | PeerTube-c46edbc2f6ca310b2f0331f979ac6caf27f6eb92.tar.gz PeerTube-c46edbc2f6ca310b2f0331f979ac6caf27f6eb92.tar.zst PeerTube-c46edbc2f6ca310b2f0331f979ac6caf27f6eb92.zip |
Fetch outbox to grab old activities tests
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video.ts | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 3b7e83779..9b411a92e 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -46,6 +46,7 @@ import { TagInstance } from './tag-interface' | |||
46 | import { VideoFileInstance, VideoFileModel } from './video-file-interface' | 46 | import { VideoFileInstance, VideoFileModel } from './video-file-interface' |
47 | import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' | 47 | import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' |
48 | import { sendDeleteVideo } from '../../lib/index' | 48 | import { sendDeleteVideo } from '../../lib/index' |
49 | import * as Bluebird from 'bluebird' | ||
49 | 50 | ||
50 | const Buffer = safeBuffer.Buffer | 51 | const Buffer = safeBuffer.Buffer |
51 | 52 | ||
@@ -786,14 +787,21 @@ list = function () { | |||
786 | } | 787 | } |
787 | 788 | ||
788 | listAllAndSharedByAccountForOutbox = function (accountId: number, start: number, count: number) { | 789 | listAllAndSharedByAccountForOutbox = function (accountId: number, start: number, count: number) { |
789 | const queryVideo = 'SELECT "Video"."id" FROM "Videos" AS "Video" ' + | 790 | function getRawQuery (select: string) { |
790 | 'INNER JOIN "VideoChannels" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' + | 791 | const queryVideo = 'SELECT ' + select + ' FROM "Videos" AS "Video" ' + |
791 | 'WHERE "VideoChannel"."accountId" = ' + accountId | 792 | 'INNER JOIN "VideoChannels" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' + |
792 | const queryVideoShare = 'SELECT "Video"."id" FROM "VideoShares" AS "VideoShare" ' + | 793 | 'WHERE "VideoChannel"."accountId" = ' + accountId |
793 | 'INNER JOIN "Videos" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' + | 794 | const queryVideoShare = 'SELECT ' + select + ' FROM "VideoShares" AS "VideoShare" ' + |
794 | 'INNER JOIN "VideoChannels" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' + | 795 | 'INNER JOIN "Videos" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' + |
795 | 'WHERE "VideoShare"."accountId" = ' + accountId | 796 | 'WHERE "VideoShare"."accountId" = ' + accountId |
796 | const rawQuery = `(${queryVideo}) UNION (${queryVideoShare}) LIMIT ${count} OFFSET ${start}` | 797 | |
798 | let rawQuery = `(${queryVideo}) UNION (${queryVideoShare})` | ||
799 | |||
800 | return rawQuery | ||
801 | } | ||
802 | |||
803 | const rawQuery = getRawQuery('"Video"."id"') | ||
804 | const rawCountQuery = getRawQuery('COUNT("Video"."id") as "total"') | ||
797 | 805 | ||
798 | const query = { | 806 | const query = { |
799 | distinct: true, | 807 | distinct: true, |
@@ -825,10 +833,20 @@ listAllAndSharedByAccountForOutbox = function (accountId: number, start: number, | |||
825 | ] | 833 | ] |
826 | } | 834 | } |
827 | 835 | ||
828 | return Video.findAndCountAll(query).then(({ rows, count }) => { | 836 | return Bluebird.all([ |
837 | Video.findAll(query), | ||
838 | Video['sequelize'].query(rawCountQuery, { type: Sequelize.QueryTypes.SELECT }) | ||
839 | ]).then(([ rows, totals ]) => { | ||
840 | // totals: totalVideos + totalVideoShares | ||
841 | let totalVideos = 0 | ||
842 | let totalVideoShares = 0 | ||
843 | if (totals[0]) totalVideos = parseInt(totals[0].total, 10) | ||
844 | if (totals[1]) totalVideoShares = parseInt(totals[1].total, 10) | ||
845 | |||
846 | const total = totalVideos + totalVideoShares | ||
829 | return { | 847 | return { |
830 | data: rows, | 848 | data: rows, |
831 | total: count | 849 | total: total |
832 | } | 850 | } |
833 | }) | 851 | }) |
834 | } | 852 | } |