aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-08-18 14:21:04 +0200
committerChocobozzz <me@florianbigard.com>2023-08-18 14:21:04 +0200
commit0d87602a205835c174c4c6b864443fcf5081bfd0 (patch)
tree675ee78222172602215be06683dbba38fa8f6e71
parent273d57023becd32c2728ace16341e99f242ff387 (diff)
downloadPeerTube-0d87602a205835c174c4c6b864443fcf5081bfd0.tar.gz
PeerTube-0d87602a205835c174c4c6b864443fcf5081bfd0.tar.zst
PeerTube-0d87602a205835c174c4c6b864443fcf5081bfd0.zip
Optimize update host script
-rwxr-xr-xserver/scripts/update-host.ts32
1 files changed, 22 insertions, 10 deletions
diff --git a/server/scripts/update-host.ts b/server/scripts/update-host.ts
index 52ac4947a..d5c378e68 100755
--- a/server/scripts/update-host.ts
+++ b/server/scripts/update-host.ts
@@ -16,6 +16,7 @@ import { VideoChannelModel } from '@server/models/video/video-channel.js'
16import { VideoCommentModel } from '@server/models/video/video-comment.js' 16import { VideoCommentModel } from '@server/models/video/video-comment.js'
17import { VideoShareModel } from '@server/models/video/video-share.js' 17import { VideoShareModel } from '@server/models/video/video-share.js'
18import { VideoModel } from '@server/models/video/video.js' 18import { VideoModel } from '@server/models/video/video.js'
19import { MActorAccount } from '@server/types/models/index.js'
19 20
20run() 21run()
21 .then(() => process.exit(0)) 22 .then(() => process.exit(0))
@@ -30,7 +31,7 @@ async function run () {
30 const serverAccount = await getServerActor() 31 const serverAccount = await getServerActor()
31 32
32 { 33 {
33 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined) 34 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined, 0, 1)
34 const hasFollowing = res.total > 0 35 const hasFollowing = res.total > 0
35 36
36 if (hasFollowing === true) { 37 if (hasFollowing === true) {
@@ -40,7 +41,10 @@ async function run () {
40 41
41 console.log('Updating actors.') 42 console.log('Updating actors.')
42 43
43 const actors: ActorModel[] = await ActorModel.unscoped().findAll({ 44 const actors: MActorAccount[] = await ActorModel.unscoped().findAll({
45 where: {
46 serverId: null
47 },
44 include: [ 48 include: [
45 { 49 {
46 model: VideoChannelModel.unscoped(), 50 model: VideoChannelModel.unscoped(),
@@ -53,8 +57,6 @@ async function run () {
53 ] 57 ]
54 }) 58 })
55 for (const actor of actors) { 59 for (const actor of actors) {
56 if (actor.isOwned() === false) continue
57
58 console.log('Updating actor ' + actor.url) 60 console.log('Updating actor ' + actor.url)
59 61
60 const newUrl = actor.Account 62 const newUrl = actor.Account
@@ -74,11 +76,18 @@ async function run () {
74 console.log('Updating video shares.') 76 console.log('Updating video shares.')
75 77
76 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({ 78 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
77 include: [ VideoModel.unscoped(), ActorModel.unscoped() ] 79 include: [
80 {
81 model: VideoModel.unscoped(),
82 where: {
83 remote: false
84 },
85 required: true
86 },
87 ActorModel.unscoped()
88 ]
78 }) 89 })
79 for (const videoShare of videoShares) { 90 for (const videoShare of videoShares) {
80 if (videoShare.Video.isOwned() === false) continue
81
82 console.log('Updating video share ' + videoShare.url) 91 console.log('Updating video share ' + videoShare.url)
83 92
84 videoShare.url = getLocalVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video) 93 videoShare.url = getLocalVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
@@ -93,17 +102,20 @@ async function run () {
93 }, 102 },
94 { 103 {
95 model: AccountModel.unscoped(), 104 model: AccountModel.unscoped(),
105 required: true,
96 include: [ 106 include: [
97 { 107 {
98 model: ActorModel.unscoped() 108 model: ActorModel.unscoped(),
109 where: {
110 serverId: null
111 },
112 required: true
99 } 113 }
100 ] 114 ]
101 } 115 }
102 ] 116 ]
103 }) 117 })
104 for (const comment of videoComments) { 118 for (const comment of videoComments) {
105 if (comment.isOwned() === false) continue
106
107 console.log('Updating comment ' + comment.url) 119 console.log('Updating comment ' + comment.url)
108 120
109 comment.url = getLocalVideoCommentActivityPubUrl(comment.Video, comment) 121 comment.url = getLocalVideoCommentActivityPubUrl(comment.Video, comment)