diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/schedulers/update-videos-scheduler.ts | 21 | ||||
-rw-r--r-- | server/models/video/schedule-video-update.ts | 24 | ||||
-rw-r--r-- | server/types/models/video/schedule-video-update.ts | 8 |
3 files changed, 15 insertions, 38 deletions
diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts index 3e75babcb..e61d4c2ac 100644 --- a/server/lib/schedulers/update-videos-scheduler.ts +++ b/server/lib/schedulers/update-videos-scheduler.ts | |||
@@ -7,6 +7,7 @@ import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' | |||
7 | import { Notifier } from '../notifier' | 7 | import { Notifier } from '../notifier' |
8 | import { sequelizeTypescript } from '../../initializers/database' | 8 | import { sequelizeTypescript } from '../../initializers/database' |
9 | import { MVideoFullLight } from '@server/types/models' | 9 | import { MVideoFullLight } from '@server/types/models' |
10 | import { VideoModel } from '@server/models/video/video' | ||
10 | 11 | ||
11 | export class UpdateVideosScheduler extends AbstractScheduler { | 12 | export class UpdateVideosScheduler extends AbstractScheduler { |
12 | 13 | ||
@@ -25,12 +26,13 @@ export class UpdateVideosScheduler extends AbstractScheduler { | |||
25 | private async updateVideos () { | 26 | private async updateVideos () { |
26 | if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined | 27 | if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined |
27 | 28 | ||
28 | const publishedVideos = await sequelizeTypescript.transaction(async t => { | 29 | const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate() |
29 | const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate(t) | 30 | const publishedVideos: MVideoFullLight[] = [] |
30 | const publishedVideos: MVideoFullLight[] = [] | 31 | |
32 | for (const schedule of schedules) { | ||
33 | await sequelizeTypescript.transaction(async t => { | ||
34 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(schedule.videoId, t) | ||
31 | 35 | ||
32 | for (const schedule of schedules) { | ||
33 | const video = schedule.Video | ||
34 | logger.info('Executing scheduled video update on %s.', video.uuid) | 36 | logger.info('Executing scheduled video update on %s.', video.uuid) |
35 | 37 | ||
36 | if (schedule.privacy) { | 38 | if (schedule.privacy) { |
@@ -42,16 +44,13 @@ export class UpdateVideosScheduler extends AbstractScheduler { | |||
42 | await federateVideoIfNeeded(video, isNewVideo, t) | 44 | await federateVideoIfNeeded(video, isNewVideo, t) |
43 | 45 | ||
44 | if (wasConfidentialVideo) { | 46 | if (wasConfidentialVideo) { |
45 | const videoToPublish: MVideoFullLight = Object.assign(video, { ScheduleVideoUpdate: schedule, UserVideoHistories: [] }) | 47 | publishedVideos.push(video) |
46 | publishedVideos.push(videoToPublish) | ||
47 | } | 48 | } |
48 | } | 49 | } |
49 | 50 | ||
50 | await schedule.destroy({ transaction: t }) | 51 | await schedule.destroy({ transaction: t }) |
51 | } | 52 | }) |
52 | 53 | } | |
53 | return publishedVideos | ||
54 | }) | ||
55 | 54 | ||
56 | for (const v of publishedVideos) { | 55 | for (const v of publishedVideos) { |
57 | Notifier.Instance.notifyOnNewVideoIfNeeded(v) | 56 | Notifier.Instance.notifyOnNewVideoIfNeeded(v) |
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts index b0952c431..d462c20c7 100644 --- a/server/models/video/schedule-video-update.ts +++ b/server/models/video/schedule-video-update.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { Op, Transaction } from 'sequelize' | 1 | import { Op, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MScheduleVideoUpdateFormattable, MScheduleVideoUpdateVideoAll } from '@server/types/models' | 3 | import { MScheduleVideoUpdateFormattable, MScheduleVideoUpdate } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/core-utils' |
5 | import { VideoPrivacy } from '../../../shared/models/videos' | 5 | import { VideoPrivacy } from '../../../shared/models/videos' |
6 | import { ScopeNames as VideoScopeNames, VideoModel } from './video' | 6 | import { VideoModel } from './video' |
7 | 7 | ||
8 | @Table({ | 8 | @Table({ |
9 | tableName: 'scheduleVideoUpdate', | 9 | tableName: 'scheduleVideoUpdate', |
@@ -62,31 +62,17 @@ export class ScheduleVideoUpdateModel extends Model<Partial<AttributesOnly<Sched | |||
62 | .then(res => !!res) | 62 | .then(res => !!res) |
63 | } | 63 | } |
64 | 64 | ||
65 | static listVideosToUpdate (t: Transaction) { | 65 | static listVideosToUpdate (transaction?: Transaction) { |
66 | const query = { | 66 | const query = { |
67 | where: { | 67 | where: { |
68 | updateAt: { | 68 | updateAt: { |
69 | [Op.lte]: new Date() | 69 | [Op.lte]: new Date() |
70 | } | 70 | } |
71 | }, | 71 | }, |
72 | include: [ | 72 | transaction |
73 | { | ||
74 | model: VideoModel.scope( | ||
75 | [ | ||
76 | VideoScopeNames.WITH_WEBTORRENT_FILES, | ||
77 | VideoScopeNames.WITH_STREAMING_PLAYLISTS, | ||
78 | VideoScopeNames.WITH_ACCOUNT_DETAILS, | ||
79 | VideoScopeNames.WITH_BLACKLISTED, | ||
80 | VideoScopeNames.WITH_THUMBNAILS, | ||
81 | VideoScopeNames.WITH_TAGS | ||
82 | ] | ||
83 | ) | ||
84 | } | ||
85 | ], | ||
86 | transaction: t | ||
87 | } | 73 | } |
88 | 74 | ||
89 | return ScheduleVideoUpdateModel.findAll<MScheduleVideoUpdateVideoAll>(query) | 75 | return ScheduleVideoUpdateModel.findAll<MScheduleVideoUpdate>(query) |
90 | } | 76 | } |
91 | 77 | ||
92 | static deleteByVideoId (videoId: number, t: Transaction) { | 78 | static deleteByVideoId (videoId: number, t: Transaction) { |
diff --git a/server/types/models/video/schedule-video-update.ts b/server/types/models/video/schedule-video-update.ts index 5d2936000..39fd73501 100644 --- a/server/types/models/video/schedule-video-update.ts +++ b/server/types/models/video/schedule-video-update.ts | |||
@@ -1,8 +1,4 @@ | |||
1 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 1 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
2 | import { PickWith } from '@shared/core-utils' | ||
3 | import { MVideoAPWithoutCaption, MVideoWithBlacklistLight } from './video' | ||
4 | |||
5 | type Use<K extends keyof ScheduleVideoUpdateModel, M> = PickWith<ScheduleVideoUpdateModel, K, M> | ||
6 | 2 | ||
7 | // ############################################################################ | 3 | // ############################################################################ |
8 | 4 | ||
@@ -10,10 +6,6 @@ export type MScheduleVideoUpdate = Omit<ScheduleVideoUpdateModel, 'Video'> | |||
10 | 6 | ||
11 | // ############################################################################ | 7 | // ############################################################################ |
12 | 8 | ||
13 | export type MScheduleVideoUpdateVideoAll = | ||
14 | MScheduleVideoUpdate & | ||
15 | Use<'Video', MVideoAPWithoutCaption & MVideoWithBlacklistLight> | ||
16 | |||
17 | // Format for API or AP object | 9 | // Format for API or AP object |
18 | 10 | ||
19 | export type MScheduleVideoUpdateFormattable = Pick<MScheduleVideoUpdate, 'updateAt' | 'privacy'> | 11 | export type MScheduleVideoUpdateFormattable = Pick<MScheduleVideoUpdate, 'updateAt' | 'privacy'> |