2021-08-27 07:32:44 -05:00
|
|
|
import { literal, Op } from 'sequelize'
|
2024-02-22 03:12:04 -06:00
|
|
|
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Table } from 'sequelize-typescript'
|
2023-07-31 07:34:36 -05:00
|
|
|
import { VideoModel } from '../video/video.js'
|
2024-02-22 03:12:04 -06:00
|
|
|
import { SequelizeModel } from '../shared/index.js'
|
2018-08-29 09:26:25 -05:00
|
|
|
|
2022-04-05 08:15:09 -05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Aggregate views of all videos federated with our instance
|
|
|
|
* Mainly used by the trending/hot algorithms
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-08-29 09:26:25 -05:00
|
|
|
@Table({
|
|
|
|
tableName: 'videoView',
|
2019-04-26 02:16:43 -05:00
|
|
|
updatedAt: false,
|
2018-08-29 09:26:25 -05:00
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'videoId' ]
|
2018-09-04 08:25:02 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'startDate' ]
|
2018-08-29 09:26:25 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2024-02-22 03:12:04 -06:00
|
|
|
export class VideoViewModel extends SequelizeModel<VideoViewModel> {
|
2018-08-29 09:26:25 -05:00
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
2021-08-27 07:32:44 -05:00
|
|
|
@Column(DataType.DATE)
|
2018-08-29 09:26:25 -05:00
|
|
|
startDate: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
2021-08-27 07:32:44 -05:00
|
|
|
@Column(DataType.DATE)
|
2018-08-29 09:26:25 -05:00
|
|
|
endDate: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
views: number
|
|
|
|
|
|
|
|
@ForeignKey(() => VideoModel)
|
|
|
|
@Column
|
|
|
|
videoId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => VideoModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
2023-07-31 07:34:36 -05:00
|
|
|
Video: Awaited<VideoModel>
|
2018-08-29 09:26:25 -05:00
|
|
|
|
2019-04-11 10:33:36 -05:00
|
|
|
static removeOldRemoteViewsHistory (beforeDate: string) {
|
|
|
|
const query = {
|
|
|
|
where: {
|
|
|
|
startDate: {
|
2021-08-27 07:32:44 -05:00
|
|
|
[Op.lt]: beforeDate
|
2019-04-11 10:33:36 -05:00
|
|
|
},
|
|
|
|
videoId: {
|
2021-08-27 07:32:44 -05:00
|
|
|
[Op.in]: literal('(SELECT "id" FROM "video" WHERE "remote" IS TRUE)')
|
2019-04-11 10:33:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VideoViewModel.destroy(query)
|
|
|
|
}
|
2018-08-29 09:26:25 -05:00
|
|
|
}
|