1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

Add ability to delete old remote views

This commit is contained in:
Chocobozzz 2019-04-11 17:33:36 +02:00
parent 7b293f2868
commit cda03765fe
No known key found for this signature in database
GPG key ID: 583A612D890159BE
15 changed files with 237 additions and 26 deletions

View file

@ -48,6 +48,20 @@ function setPlaylistField (serverNumber: number, uuid: string, field: string, va
return seq.query(`UPDATE "videoPlaylist" SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options)
}
async function countVideoViewsOf (serverNumber: number, uuid: string) {
const seq = getSequelize(serverNumber)
// tslint:disable
const query = `SELECT SUM("videoView"."views") AS "total" FROM "videoView" INNER JOIN "video" ON "video"."id" = "videoView"."videoId" WHERE "video"."uuid" = '${uuid}'`
const options = { type: Sequelize.QueryTypes.SELECT }
const [ { total } ] = await seq.query(query, options)
if (!total) return 0
return parseInt(total, 10)
}
async function closeAllSequelize (servers: any[]) {
for (let i = 1; i <= servers.length; i++) {
if (sequelizes[ i ]) {
@ -61,5 +75,6 @@ export {
setVideoField,
setPlaylistField,
setActorField,
countVideoViewsOf,
closeAllSequelize
}