diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-19 14:13:53 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-03-19 14:13:53 +0100 |
commit | 9f79ade627f0044606a9fbbe16ca0154661d12b9 (patch) | |
tree | ccfc1876da591bc52cbb4b8ccddedbeae7876679 /server/models/video | |
parent | 0e0c745b62b2f18e228328e8c4f95b17e54f7a5e (diff) | |
download | PeerTube-9f79ade627f0044606a9fbbe16ca0154661d12b9.tar.gz PeerTube-9f79ade627f0044606a9fbbe16ca0154661d12b9.tar.zst PeerTube-9f79ade627f0044606a9fbbe16ca0154661d12b9.zip |
Refresh playlists
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-playlist.ts | 15 | ||||
-rw-r--r-- | server/models/video/video.ts | 11 |
2 files changed, 17 insertions, 9 deletions
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 { | |||
17 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
18 | import * as Sequelize from 'sequelize' | 18 | import * as Sequelize from 'sequelize' |
19 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 19 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
20 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, throwIfNotValid } from '../utils' | 20 | import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils' |
21 | import { | 21 | import { |
22 | isVideoPlaylistDescriptionValid, | 22 | isVideoPlaylistDescriptionValid, |
23 | isVideoPlaylistNameValid, | 23 | isVideoPlaylistNameValid, |
@@ -25,6 +25,7 @@ import { | |||
25 | } from '../../helpers/custom-validators/video-playlists' | 25 | } from '../../helpers/custom-validators/video-playlists' |
26 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 26 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
27 | import { | 27 | import { |
28 | ACTIVITY_PUB, | ||
28 | CONFIG, | 29 | CONFIG, |
29 | CONSTRAINTS_FIELDS, | 30 | CONSTRAINTS_FIELDS, |
30 | STATIC_PATHS, | 31 | STATIC_PATHS, |
@@ -429,10 +430,22 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
429 | .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err })) | 430 | .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err })) |
430 | } | 431 | } |
431 | 432 | ||
433 | setAsRefreshed () { | ||
434 | this.changed('updatedAt', true) | ||
435 | |||
436 | return this.save() | ||
437 | } | ||
438 | |||
432 | isOwned () { | 439 | isOwned () { |
433 | return this.OwnerAccount.isOwned() | 440 | return this.OwnerAccount.isOwned() |
434 | } | 441 | } |
435 | 442 | ||
443 | isOutdated () { | ||
444 | if (this.isOwned()) return false | ||
445 | |||
446 | return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL) | ||
447 | } | ||
448 | |||
436 | toFormattedJSON (): VideoPlaylist { | 449 | toFormattedJSON (): VideoPlaylist { |
437 | return { | 450 | return { |
438 | id: this.id, | 451 | 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 { | |||
77 | buildTrigramSearchIndex, | 77 | buildTrigramSearchIndex, |
78 | buildWhereIdOrUUID, | 78 | buildWhereIdOrUUID, |
79 | createSimilarityAttribute, | 79 | createSimilarityAttribute, |
80 | getVideoSort, | 80 | getVideoSort, isOutdated, |
81 | throwIfNotValid | 81 | throwIfNotValid |
82 | } from '../utils' | 82 | } from '../utils' |
83 | import { TagModel } from './tag' | 83 | import { TagModel } from './tag' |
@@ -1547,7 +1547,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1547 | attributes: query.attributes, | 1547 | attributes: query.attributes, |
1548 | order: [ // Keep original order | 1548 | order: [ // Keep original order |
1549 | Sequelize.literal( | 1549 | Sequelize.literal( |
1550 | ids.map(id => `"VideoModel".id = ${id} DESC`).join(', ') | 1550 | ids.map(id => `"VideoModel".id = ${id}`).join(', ') |
1551 | ) | 1551 | ) |
1552 | ] | 1552 | ] |
1553 | } | 1553 | } |
@@ -1767,12 +1767,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1767 | isOutdated () { | 1767 | isOutdated () { |
1768 | if (this.isOwned()) return false | 1768 | if (this.isOwned()) return false |
1769 | 1769 | ||
1770 | const now = Date.now() | 1770 | return isOutdated(this, ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL) |
1771 | const createdAtTime = this.createdAt.getTime() | ||
1772 | const updatedAtTime = this.updatedAt.getTime() | ||
1773 | |||
1774 | return (now - createdAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL && | ||
1775 | (now - updatedAtTime) > ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL | ||
1776 | } | 1771 | } |
1777 | 1772 | ||
1778 | setAsRefreshed () { | 1773 | setAsRefreshed () { |