aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/request/request-video-qadu-scheduler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/request/request-video-qadu-scheduler.ts')
-rw-r--r--server/lib/request/request-video-qadu-scheduler.ts31
1 files changed, 25 insertions, 6 deletions
diff --git a/server/lib/request/request-video-qadu-scheduler.ts b/server/lib/request/request-video-qadu-scheduler.ts
index 5ec7de9c2..988165170 100644
--- a/server/lib/request/request-video-qadu-scheduler.ts
+++ b/server/lib/request/request-video-qadu-scheduler.ts
@@ -1,7 +1,7 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { database as db } from '../../initializers/database' 3import { database as db } from '../../initializers/database'
4import { AbstractRequestScheduler } from './abstract-request-scheduler' 4import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler'
5import { logger } from '../../helpers' 5import { logger } from '../../helpers'
6import { 6import {
7 REQUESTS_VIDEO_QADU_LIMIT_PODS, 7 REQUESTS_VIDEO_QADU_LIMIT_PODS,
@@ -9,8 +9,27 @@ import {
9 REQUEST_VIDEO_QADU_ENDPOINT, 9 REQUEST_VIDEO_QADU_ENDPOINT,
10 REQUEST_VIDEO_QADU_TYPES 10 REQUEST_VIDEO_QADU_TYPES
11} from '../../initializers' 11} from '../../initializers'
12import { RequestsVideoQaduGrouped } from '../../models' 12import { RequestsVideoQaduGrouped, PodInstance } from '../../models'
13import { RequestVideoQaduType } from '../../../shared' 13import { RemoteQaduVideoRequest, RequestVideoQaduType } from '../../../shared'
14
15// We create a custom interface because we need "videos" attribute for our computations
16interface RequestsObjectsCustom<U> extends RequestsObjects<U> {
17 [ id: string ]: {
18 toPod: PodInstance
19 endpoint: string
20 ids: number[] // ids
21 datas: U[]
22
23 videos: {
24 [ id: string ]: {
25 remoteId: string
26 likes?: number
27 dislikes?: number
28 views?: number
29 }
30 }
31 }
32}
14 33
15export type RequestVideoQaduSchedulerOptions = { 34export type RequestVideoQaduSchedulerOptions = {
16 type: RequestVideoQaduType 35 type: RequestVideoQaduType
@@ -37,8 +56,8 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler<RequestsVideoQa
37 return db.RequestVideoQadu 56 return db.RequestVideoQadu
38 } 57 }
39 58
40 buildRequestObjects (requests: RequestsVideoQaduGrouped) { 59 buildRequestsObjects (requests: RequestsVideoQaduGrouped) {
41 const requestsToMakeGrouped = {} 60 const requestsToMakeGrouped: RequestsObjectsCustom<RemoteQaduVideoRequest> = {}
42 61
43 Object.keys(requests).forEach(toPodId => { 62 Object.keys(requests).forEach(toPodId => {
44 requests[toPodId].forEach(data => { 63 requests[toPodId].forEach(data => {
@@ -59,7 +78,7 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler<RequestsVideoQa
59 78
60 // Maybe another attribute was filled for this video 79 // Maybe another attribute was filled for this video
61 let videoData = requestsToMakeGrouped[hashKey].videos[video.id] 80 let videoData = requestsToMakeGrouped[hashKey].videos[video.id]
62 if (!videoData) videoData = {} 81 if (!videoData) videoData = { remoteId: null }
63 82
64 switch (request.type) { 83 switch (request.type) {
65 case REQUEST_VIDEO_QADU_TYPES.LIKES: 84 case REQUEST_VIDEO_QADU_TYPES.LIKES: