diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/miscs/sql.ts | 39 | ||||
-rw-r--r-- | shared/extra-utils/server/jobs.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 2 | ||||
-rw-r--r-- | shared/models/server/job.model.ts | 1 |
4 files changed, 42 insertions, 3 deletions
diff --git a/shared/extra-utils/miscs/sql.ts b/shared/extra-utils/miscs/sql.ts index e68812e1b..740f0c2d6 100644 --- a/shared/extra-utils/miscs/sql.ts +++ b/shared/extra-utils/miscs/sql.ts | |||
@@ -24,6 +24,25 @@ function getSequelize (internalServerNumber: number) { | |||
24 | return seq | 24 | return seq |
25 | } | 25 | } |
26 | 26 | ||
27 | function deleteAll (internalServerNumber: number, table: string) { | ||
28 | const seq = getSequelize(internalServerNumber) | ||
29 | |||
30 | const options = { type: QueryTypes.DELETE } | ||
31 | |||
32 | return seq.query(`DELETE FROM "${table}"`, options) | ||
33 | } | ||
34 | |||
35 | async function getCount (internalServerNumber: number, table: string) { | ||
36 | const seq = getSequelize(internalServerNumber) | ||
37 | |||
38 | const options = { type: QueryTypes.SELECT as QueryTypes.SELECT } | ||
39 | |||
40 | const [ { total } ] = await seq.query<{ total: string }>(`SELECT COUNT(*) as total FROM "${table}"`, options) | ||
41 | if (total === null) return 0 | ||
42 | |||
43 | return parseInt(total, 10) | ||
44 | } | ||
45 | |||
27 | function setActorField (internalServerNumber: number, to: string, field: string, value: string) { | 46 | function setActorField (internalServerNumber: number, to: string, field: string, value: string) { |
28 | const seq = getSequelize(internalServerNumber) | 47 | const seq = getSequelize(internalServerNumber) |
29 | 48 | ||
@@ -63,6 +82,20 @@ async function countVideoViewsOf (internalServerNumber: number, uuid: string) { | |||
63 | return parseInt(total + '', 10) | 82 | return parseInt(total + '', 10) |
64 | } | 83 | } |
65 | 84 | ||
85 | function selectQuery (internalServerNumber: number, query: string) { | ||
86 | const seq = getSequelize(internalServerNumber) | ||
87 | const options = { type: QueryTypes.SELECT as QueryTypes.SELECT } | ||
88 | |||
89 | return seq.query<any>(query, options) | ||
90 | } | ||
91 | |||
92 | function updateQuery (internalServerNumber: number, query: string) { | ||
93 | const seq = getSequelize(internalServerNumber) | ||
94 | const options = { type: QueryTypes.UPDATE as QueryTypes.UPDATE } | ||
95 | |||
96 | return seq.query(query, options) | ||
97 | } | ||
98 | |||
66 | async function closeAllSequelize (servers: ServerInfo[]) { | 99 | async function closeAllSequelize (servers: ServerInfo[]) { |
67 | for (const server of servers) { | 100 | for (const server of servers) { |
68 | if (sequelizes[server.internalServerNumber]) { | 101 | if (sequelizes[server.internalServerNumber]) { |
@@ -95,6 +128,10 @@ export { | |||
95 | setActorField, | 128 | setActorField, |
96 | countVideoViewsOf, | 129 | countVideoViewsOf, |
97 | setPluginVersion, | 130 | setPluginVersion, |
131 | selectQuery, | ||
132 | deleteAll, | ||
133 | updateQuery, | ||
98 | setActorFollowScores, | 134 | setActorFollowScores, |
99 | closeAllSequelize | 135 | closeAllSequelize, |
136 | getCount | ||
100 | } | 137 | } |
diff --git a/shared/extra-utils/server/jobs.ts b/shared/extra-utils/server/jobs.ts index 97971f960..704929bd4 100644 --- a/shared/extra-utils/server/jobs.ts +++ b/shared/extra-utils/server/jobs.ts | |||
@@ -63,6 +63,7 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
63 | else servers = serversArg as ServerInfo[] | 63 | else servers = serversArg as ServerInfo[] |
64 | 64 | ||
65 | const states: JobState[] = [ 'waiting', 'active', 'delayed' ] | 65 | const states: JobState[] = [ 'waiting', 'active', 'delayed' ] |
66 | const repeatableJobs = [ 'videos-views', 'activitypub-cleaner' ] | ||
66 | let pendingRequests: boolean | 67 | let pendingRequests: boolean |
67 | 68 | ||
68 | function tasksBuilder () { | 69 | function tasksBuilder () { |
@@ -79,7 +80,7 @@ async function waitJobs (serversArg: ServerInfo[] | ServerInfo) { | |||
79 | count: 10, | 80 | count: 10, |
80 | sort: '-createdAt' | 81 | sort: '-createdAt' |
81 | }).then(res => res.body.data) | 82 | }).then(res => res.body.data) |
82 | .then((jobs: Job[]) => jobs.filter(j => j.type !== 'videos-views')) | 83 | .then((jobs: Job[]) => jobs.filter(j => !repeatableJobs.includes(j.type))) |
83 | .then(jobs => { | 84 | .then(jobs => { |
84 | if (jobs.length !== 0) { | 85 | if (jobs.length !== 0) { |
85 | pendingRequests = true | 86 | pendingRequests = true |
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 0b6a54046..67fe82d41 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -498,7 +498,7 @@ function updateVideo ( | |||
498 | }) | 498 | }) |
499 | } | 499 | } |
500 | 500 | ||
501 | function rateVideo (url: string, accessToken: string, id: number, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { | 501 | function rateVideo (url: string, accessToken: string, id: number | string, rating: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { |
502 | const path = '/api/v1/videos/' + id + '/rate' | 502 | const path = '/api/v1/videos/' + id + '/rate' |
503 | 503 | ||
504 | return request(url) | 504 | return request(url) |
diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index c693827b0..83ef84457 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts | |||
@@ -8,6 +8,7 @@ export type JobType = | |||
8 | | 'activitypub-http-unicast' | 8 | | 'activitypub-http-unicast' |
9 | | 'activitypub-http-broadcast' | 9 | | 'activitypub-http-broadcast' |
10 | | 'activitypub-http-fetcher' | 10 | | 'activitypub-http-fetcher' |
11 | | 'activitypub-cleaner' | ||
11 | | 'activitypub-follow' | 12 | | 'activitypub-follow' |
12 | | 'video-file-import' | 13 | | 'video-file-import' |
13 | | 'video-transcoding' | 14 | | 'video-transcoding' |