Merge branch 'release/v1.3.0' into develop

This commit is contained in:
Chocobozzz 2019-05-21 13:32:00 +02:00
commit 21d141c296
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 79 additions and 29 deletions

View File

@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const LAST_MIGRATION_VERSION = 375 const LAST_MIGRATION_VERSION = 380
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -0,0 +1,29 @@
import * as Sequelize from 'sequelize'
async function up (utils: {
transaction: Sequelize.Transaction,
queryInterface: Sequelize.QueryInterface,
sequelize: Sequelize.Sequelize,
db: any
}): Promise<void> {
try {
await utils.queryInterface.removeColumn('application', 'createdAt')
} catch { /* the column could not exist */ }
try {
await utils.queryInterface.removeColumn('application', 'updatedAt')
} catch { /* the column could not exist */ }
try {
await utils.queryInterface.removeColumn('videoView', 'updatedAt')
} catch { /* the column could not exist */ }
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}

View File

@ -27,6 +27,12 @@ async function processVideosViews () {
logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour) logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour)
try { try {
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
if (!video) {
logger.debug('Video %d does not exist anymore, skipping videos view addition.', videoId)
continue
}
await VideoViewModel.create({ await VideoViewModel.create({
startDate, startDate,
endDate, endDate,
@ -34,7 +40,6 @@ async function processVideosViews () {
videoId videoId
}) })
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
if (video.isOwned()) { if (video.isOwned()) {
// If this is a remote video, the origin instance will send us an update // If this is a remote video, the origin instance will send us an update
await VideoModel.incrementViews(videoId, views) await VideoModel.incrementViews(videoId, views)
@ -44,13 +49,13 @@ async function processVideosViews () {
await federateVideoIfNeeded(video, false) await federateVideoIfNeeded(video, false)
} }
} catch (err) { } catch (err) {
logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) logger.error('Cannot create video views for video %d in hour %d.', videoId, hour, { err })
} }
} }
await Redis.Instance.deleteVideoViews(videoId, hour) await Redis.Instance.deleteVideoViews(videoId, hour)
} catch (err) { } catch (err) {
logger.error('Cannot update video views of video %d in hour %d.', videoId, hour) logger.error('Cannot update video views of video %d in hour %d.', videoId, hour, { err })
} }
} }
} }

View File

@ -1,11 +1,12 @@
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { getSortOnModel, SortType, throwIfNotValid } from '../utils' import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
import { VideoModel, ScopeNames as VideoModelScopeNames } from './video' import { ScopeNames as VideoModelScopeNames, VideoModel } from './video'
import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel' import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel'
import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist'
import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos'
import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { FindOptions } from 'sequelize' import { FindOptions } from 'sequelize'
import { ThumbnailModel } from './thumbnail'
@Table({ @Table({
tableName: 'videoBlacklist', tableName: 'videoBlacklist',
@ -52,35 +53,50 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
Video: VideoModel Video: VideoModel
static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) { static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) {
const query: FindOptions = { function buildBaseQuery (): FindOptions {
offset: start, return {
limit: count, offset: start,
order: getSortOnModel(sort.sortModel, sort.sortValue), limit: count,
include: [ order: getSortOnModel(sort.sortModel, sort.sortValue)
{ }
model: VideoModel.scope(VideoModelScopeNames.WITH_THUMBNAILS),
required: true,
include: [
{
model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
required: true
}
]
}
]
} }
const countQuery = buildBaseQuery()
const findQuery = buildBaseQuery()
findQuery.subQuery = false
findQuery.include = [
{
model: VideoModel,
required: true,
include: [
{
model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
required: true
},
{
model: ThumbnailModel,
attributes: [ 'type', 'filename' ],
required: false
}
]
}
]
if (type) { if (type) {
query.where = { type } countQuery.where = { type }
findQuery.where = { type }
} }
return VideoBlacklistModel.findAndCountAll(query) return Promise.all([
.then(({ rows, count }) => { VideoBlacklistModel.count(countQuery),
return { VideoBlacklistModel.findAll(findQuery)
data: rows, ]).then(([ count, rows ]) => {
total: count return {
} data: rows,
}) total: count
}
})
} }
static loadByVideoId (id: number) { static loadByVideoId (id: number) {