From 9f79ade627f0044606a9fbbe16ca0154661d12b9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Mar 2019 14:13:53 +0100 Subject: Refresh playlists --- server/models/video/video-playlist.ts | 15 ++++++++++++++- server/models/video/video.ts | 11 +++-------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 7dbe4ce8d..08e4d32c8 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -17,7 +17,7 @@ import { } from 'sequelize-typescript' import * as Sequelize from 'sequelize' import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' -import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, throwIfNotValid } from '../utils' +import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils' import { isVideoPlaylistDescriptionValid, isVideoPlaylistNameValid, @@ -25,6 +25,7 @@ import { } from '../../helpers/custom-validators/video-playlists' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { + ACTIVITY_PUB, CONFIG, CONSTRAINTS_FIELDS, STATIC_PATHS, @@ -429,10 +430,22 @@ export class VideoPlaylistModel extends Model { .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err })) } + setAsRefreshed () { + this.changed('updatedAt', true) + + return this.save() + } + isOwned () { return this.OwnerAccount.isOwned() } + isOutdated () { + if (this.isOwned()) return false + + return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL) + } + toFormattedJSON (): VideoPlaylist { return { id: this.id, diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 946be6095..fb037c21a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -77,7 +77,7 @@ import { buildTrigramSearchIndex, buildWhereIdOrUUID, createSimilarityAttribute, - getVideoSort, + getVideoSort, isOutdated, throwIfNotValid } from '../utils' import { TagModel } from './tag' @@ -1547,7 +1547,7 @@ export class VideoModel extends Model { attributes: query.attributes, order: [ // Keep original order Sequelize.literal( - ids.map(id => `"VideoModel".id = ${id} DESC`).join(', ') + ids.map(id => `"VideoModel".id = ${id}`).join(', ') ) ] } @@ -1767,12 +1767,7 @@ export class VideoModel extends Model { isOutdated () { if (this.isOwned()) return false - const now = Date.now() - const createdAtTime = this.createdAt.getTime() - const updatedAtTime = this.updatedAt.getTime() - - return (now - createdAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL && - (now - updatedAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL + return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL) } setAsRefreshed () { -- cgit v1.2.3