From 9e167724f7e933f41d9ea2e1c31772bf4c560a28 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 21 Feb 2017 21:35:59 +0100 Subject: Server: make a basic "quick and dirty update" for videos This system will be useful to to update some int video attributes (likes, dislikes, views...) The classic system is not used because we need some optimization for scaling --- server/models/video.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'server/models/video.js') diff --git a/server/models/video.js b/server/models/video.js index d0fd61eb4..daa273845 100644 --- a/server/models/video.js +++ b/server/models/video.js @@ -80,6 +80,15 @@ module.exports = function (sequelize, DataTypes) { if (res === false) throw new Error('Video duration is not valid.') } } + }, + views: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 0, + validate: { + min: 0, + isInt: true + } } }, { @@ -101,6 +110,9 @@ module.exports = function (sequelize, DataTypes) { }, { fields: [ 'infoHash' ] + }, + { + fields: [ 'views' ] } ], classMethods: { @@ -336,6 +348,7 @@ function toFormatedJSON () { magnetUri: this.generateMagnetUri(), author: this.Author.name, duration: this.duration, + views: this.views, tags: map(this.Tags, 'name'), thumbnailPath: pathUtils.join(constants.STATIC_PATHS.THUMBNAILS, this.getThumbnailName()), createdAt: this.createdAt, -- cgit v1.2.3