diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-11 14:09:33 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-11 14:09:52 +0200 |
commit | 71d4af1efc810f853e1a0d986bf758c201692594 (patch) | |
tree | 2066053638baefb6430772c2e0a0aa1774019a51 /server/models/video/sql/shared/video-model-builder.ts | |
parent | 3c79c2ce86eaf9e151ab6c2c9d1f646968a16744 (diff) | |
download | PeerTube-71d4af1efc810f853e1a0d986bf758c201692594.tar.gz PeerTube-71d4af1efc810f853e1a0d986bf758c201692594.tar.zst PeerTube-71d4af1efc810f853e1a0d986bf758c201692594.zip |
Use raw SQL for most of video queries
Diffstat (limited to 'server/models/video/sql/shared/video-model-builder.ts')
-rw-r--r-- | server/models/video/sql/shared/video-model-builder.ts | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/server/models/video/sql/shared/video-model-builder.ts b/server/models/video/sql/shared/video-model-builder.ts index 2a60dab04..467a9378a 100644 --- a/server/models/video/sql/shared/video-model-builder.ts +++ b/server/models/video/sql/shared/video-model-builder.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | 1 | ||
2 | import { logger } from '@server/helpers/logger' | ||
3 | import { AccountModel } from '@server/models/account/account' | 2 | import { AccountModel } from '@server/models/account/account' |
4 | import { ActorModel } from '@server/models/actor/actor' | 3 | import { ActorModel } from '@server/models/actor/actor' |
5 | import { ActorImageModel } from '@server/models/actor/actor-image' | 4 | import { ActorImageModel } from '@server/models/actor/actor-image' |
@@ -56,7 +55,7 @@ export class VideoModelBuilder { | |||
56 | this.reinit() | 55 | this.reinit() |
57 | 56 | ||
58 | for (const row of rows) { | 57 | for (const row of rows) { |
59 | this.buildVideo(row) | 58 | this.buildVideoAndAccount(row) |
60 | 59 | ||
61 | const videoModel = this.videosMemo[row.id] | 60 | const videoModel = this.videosMemo[row.id] |
62 | 61 | ||
@@ -131,22 +130,10 @@ export class VideoModelBuilder { | |||
131 | } | 130 | } |
132 | } | 131 | } |
133 | 132 | ||
134 | private buildVideo (row: SQLRow) { | 133 | private buildVideoAndAccount (row: SQLRow) { |
135 | if (this.videosMemo[row.id]) return | 134 | if (this.videosMemo[row.id]) return |
136 | 135 | ||
137 | // Build Channel | ||
138 | const channelModel = new VideoChannelModel(this.grab(row, this.tables.getChannelAttributes(), 'VideoChannel'), this.buildOpts) | ||
139 | channelModel.Actor = this.buildActor(row, 'VideoChannel') | ||
140 | |||
141 | const accountModel = new AccountModel(this.grab(row, this.tables.getAccountAttributes(), 'VideoChannel.Account'), this.buildOpts) | ||
142 | accountModel.Actor = this.buildActor(row, 'VideoChannel.Account') | ||
143 | |||
144 | channelModel.Account = accountModel | ||
145 | |||
146 | const videoModel = new VideoModel(this.grab(row, this.tables.getVideoAttributes(), ''), this.buildOpts) | 136 | const videoModel = new VideoModel(this.grab(row, this.tables.getVideoAttributes(), ''), this.buildOpts) |
147 | videoModel.VideoChannel = channelModel | ||
148 | |||
149 | this.videosMemo[row.id] = videoModel | ||
150 | 137 | ||
151 | videoModel.UserVideoHistories = [] | 138 | videoModel.UserVideoHistories = [] |
152 | videoModel.Thumbnails = [] | 139 | videoModel.Thumbnails = [] |
@@ -155,10 +142,29 @@ export class VideoModelBuilder { | |||
155 | videoModel.Tags = [] | 142 | videoModel.Tags = [] |
156 | videoModel.Trackers = [] | 143 | videoModel.Trackers = [] |
157 | 144 | ||
145 | this.buildAccount(row, videoModel) | ||
146 | |||
147 | this.videosMemo[row.id] = videoModel | ||
148 | |||
158 | // Keep rows order | 149 | // Keep rows order |
159 | this.videos.push(videoModel) | 150 | this.videos.push(videoModel) |
160 | } | 151 | } |
161 | 152 | ||
153 | private buildAccount (row: SQLRow, videoModel: VideoModel) { | ||
154 | const id = row['VideoChannel.Account.id'] | ||
155 | if (!id) return | ||
156 | |||
157 | const channelModel = new VideoChannelModel(this.grab(row, this.tables.getChannelAttributes(), 'VideoChannel'), this.buildOpts) | ||
158 | channelModel.Actor = this.buildActor(row, 'VideoChannel') | ||
159 | |||
160 | const accountModel = new AccountModel(this.grab(row, this.tables.getAccountAttributes(), 'VideoChannel.Account'), this.buildOpts) | ||
161 | accountModel.Actor = this.buildActor(row, 'VideoChannel.Account') | ||
162 | |||
163 | channelModel.Account = accountModel | ||
164 | |||
165 | videoModel.VideoChannel = channelModel | ||
166 | } | ||
167 | |||
162 | private buildActor (row: SQLRow, prefix: string) { | 168 | private buildActor (row: SQLRow, prefix: string) { |
163 | const actorPrefix = `${prefix}.Actor` | 169 | const actorPrefix = `${prefix}.Actor` |
164 | const avatarPrefix = `${actorPrefix}.Avatar` | 170 | const avatarPrefix = `${actorPrefix}.Avatar` |