aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-05-21 13:14:27 +0200
committerChocobozzz <me@florianbigard.com>2019-05-21 13:14:27 +0200
commit63dc589865fa1882d38f1d9e0050d2341869d487 (patch)
treec97359bbcc2ff6f104d5939ba891161cd03c9de0
parentac3d2e05695883dabb435868272709b955dcb77a (diff)
downloadPeerTube-63dc589865fa1882d38f1d9e0050d2341869d487.tar.gz
PeerTube-63dc589865fa1882d38f1d9e0050d2341869d487.tar.zst
PeerTube-63dc589865fa1882d38f1d9e0050d2341869d487.zip
Fix video views
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0380-cleanup-timestamps.ts29
-rw-r--r--server/lib/job-queue/handlers/video-views.ts11
3 files changed, 38 insertions, 4 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 62778ae58..b5f8fc0bc 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
14 14
15// --------------------------------------------------------------------------- 15// ---------------------------------------------------------------------------
16 16
17const LAST_MIGRATION_VERSION = 375 17const LAST_MIGRATION_VERSION = 380
18 18
19// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
20 20
diff --git a/server/initializers/migrations/0380-cleanup-timestamps.ts b/server/initializers/migrations/0380-cleanup-timestamps.ts
new file mode 100644
index 000000000..2a9fd6f02
--- /dev/null
+++ b/server/initializers/migrations/0380-cleanup-timestamps.ts
@@ -0,0 +1,29 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction,
5 queryInterface: Sequelize.QueryInterface,
6 sequelize: Sequelize.Sequelize,
7 db: any
8}): Promise<void> {
9 try {
10 await utils.queryInterface.removeColumn('application', 'createdAt')
11 } catch { /* the column could not exist */ }
12
13 try {
14 await utils.queryInterface.removeColumn('application', 'updatedAt')
15 } catch { /* the column could not exist */ }
16
17 try {
18 await utils.queryInterface.removeColumn('videoView', 'updatedAt')
19 } catch { /* the column could not exist */ }
20}
21
22function down (options) {
23 throw new Error('Not implemented.')
24}
25
26export {
27 up,
28 down
29}
diff --git a/server/lib/job-queue/handlers/video-views.ts b/server/lib/job-queue/handlers/video-views.ts
index fa1fd13b3..73fa5ed04 100644
--- a/server/lib/job-queue/handlers/video-views.ts
+++ b/server/lib/job-queue/handlers/video-views.ts
@@ -27,6 +27,12 @@ async function processVideosViews () {
27 logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour) 27 logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour)
28 28
29 try { 29 try {
30 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
31 if (!video) {
32 logger.debug('Video %d does not exist anymore, skipping videos view addition.', videoId)
33 continue
34 }
35
30 await VideoViewModel.create({ 36 await VideoViewModel.create({
31 startDate, 37 startDate,
32 endDate, 38 endDate,
@@ -34,7 +40,6 @@ async function processVideosViews () {
34 videoId 40 videoId
35 }) 41 })
36 42
37 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
38 if (video.isOwned()) { 43 if (video.isOwned()) {
39 // If this is a remote video, the origin instance will send us an update 44 // If this is a remote video, the origin instance will send us an update
40 await VideoModel.incrementViews(videoId, views) 45 await VideoModel.incrementViews(videoId, views)
@@ -44,13 +49,13 @@ async function processVideosViews () {
44 await federateVideoIfNeeded(video, false) 49 await federateVideoIfNeeded(video, false)
45 } 50 }
46 } catch (err) { 51 } catch (err) {
47 logger.debug('Cannot create video views for video %d in hour %d. Maybe the video does not exist anymore?', videoId, hour) 52 logger.error('Cannot create video views for video %d in hour %d.', videoId, hour, { err })
48 } 53 }
49 } 54 }
50 55
51 await Redis.Instance.deleteVideoViews(videoId, hour) 56 await Redis.Instance.deleteVideoViews(videoId, hour)
52 } catch (err) { 57 } catch (err) {
53 logger.error('Cannot update video views of video %d in hour %d.', videoId, hour) 58 logger.error('Cannot update video views of video %d in hour %d.', videoId, hour, { err })
54 } 59 }
55 } 60 }
56} 61}