Browse Source

Fix video views

Chocobozzz 6 months ago
parent
commit
63dc589865
No account linked to committer's email address

+ 1
- 1
server/initializers/constants.ts View File

@@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
14 14
 
15 15
 // ---------------------------------------------------------------------------
16 16
 
17
-const LAST_MIGRATION_VERSION = 375
17
+const LAST_MIGRATION_VERSION = 380
18 18
 
19 19
 // ---------------------------------------------------------------------------
20 20
 

+ 29
- 0
server/initializers/migrations/0380-cleanup-timestamps.ts View File

@@ -0,0 +1,29 @@
1
+import * as Sequelize from 'sequelize'
2
+
3
+async 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
+
22
+function down (options) {
23
+  throw new Error('Not implemented.')
24
+}
25
+
26
+export {
27
+  up,
28
+  down
29
+}

+ 8
- 3
server/lib/job-queue/handlers/video-views.ts View File

@@ -27,6 +27,12 @@ async function processVideosViews () {
27 27
         logger.debug('Adding %d views to video %d in hour %d.', views, videoId, hour)
28 28
 
29 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 36
           await VideoViewModel.create({
31 37
             startDate,
32 38
             endDate,
@@ -34,7 +40,6 @@ async function processVideosViews () {
34 40
             videoId
35 41
           })
36 42
 
37
-          const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
38 43
           if (video.isOwned()) {
39 44
             // If this is a remote video, the origin instance will send us an update
40 45
             await VideoModel.incrementViews(videoId, views)
@@ -44,13 +49,13 @@ async function processVideosViews () {
44 49
             await federateVideoIfNeeded(video, false)
45 50
           }
46 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 56
       await Redis.Instance.deleteVideoViews(videoId, hour)
52 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
 }

Loading…
Cancel
Save