aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-01-10 09:16:33 +0100
committerChocobozzz <me@florianbigard.com>2023-01-10 09:17:23 +0100
commita8749f7c3b137f433e6944bb99fd721a6f0cfc1e (patch)
tree88046c0bfc69728f98dca7bcde4aa7e7d1308591 /server
parent57f255bebc2f55fd152c70b05b8de54e5e77da61 (diff)
downloadPeerTube-a8749f7c3b137f433e6944bb99fd721a6f0cfc1e.tar.gz
PeerTube-a8749f7c3b137f433e6944bb99fd721a6f0cfc1e.tar.zst
PeerTube-a8749f7c3b137f433e6944bb99fd721a6f0cfc1e.zip
Fix comments SQL pagination
Diffstat (limited to 'server')
-rw-r--r--server/models/video/sql/comment/video-comment-list-query-builder.ts11
-rw-r--r--server/models/video/sql/comment/video-comment-table-attributes.ts2
-rw-r--r--server/tests/api/videos/video-comments.ts23
3 files changed, 23 insertions, 13 deletions
diff --git a/server/models/video/sql/comment/video-comment-list-query-builder.ts b/server/models/video/sql/comment/video-comment-list-query-builder.ts
index f3f6910e1..49b41b6d8 100644
--- a/server/models/video/sql/comment/video-comment-list-query-builder.ts
+++ b/server/models/video/sql/comment/video-comment-list-query-builder.ts
@@ -87,8 +87,7 @@ export class VideoCommentListQueryBuilder extends AbstractRunQuery {
87 this.query = `${this.select} ` + 87 this.query = `${this.select} ` +
88 `FROM (${this.innerQuery}) AS "VideoCommentModel" ` + 88 `FROM (${this.innerQuery}) AS "VideoCommentModel" ` +
89 `${this.joins} ` + 89 `${this.joins} ` +
90 `${this.getOrder()} ` + 90 `${this.getOrder()}`
91 `${this.getLimit()}`
92 } 91 }
93 92
94 private buildInnerListQuery () { 93 private buildInnerListQuery () {
@@ -375,14 +374,6 @@ export class VideoCommentListQueryBuilder extends AbstractRunQuery {
375 return 'ORDER BY ' + orders.map(o => `"${o[0]}" ${o[1]}`).join(', ') 374 return 'ORDER BY ' + orders.map(o => `"${o[0]}" ${o[1]}`).join(', ')
376 } 375 }
377 376
378 private getLimit () {
379 if (!this.options.count) return ''
380
381 this.replacements.limit = this.options.count
382
383 return `LIMIT :limit `
384 }
385
386 private getInnerLimit () { 377 private getInnerLimit () {
387 if (!this.options.count) return '' 378 if (!this.options.count) return ''
388 379
diff --git a/server/models/video/sql/comment/video-comment-table-attributes.ts b/server/models/video/sql/comment/video-comment-table-attributes.ts
index 10e635e41..87f8750c1 100644
--- a/server/models/video/sql/comment/video-comment-table-attributes.ts
+++ b/server/models/video/sql/comment/video-comment-table-attributes.ts
@@ -38,6 +38,6 @@ export class VideoCommentTableAttributes {
38 38
39 @Memoize() 39 @Memoize()
40 getAvatarAttributes () { 40 getAvatarAttributes () {
41 return ActorImageModel.getSQLAttributes('Account->Actor->Avatars', 'Account.Actor.Avatars.id').join(', ') 41 return ActorImageModel.getSQLAttributes('Account->Actor->Avatars', 'Account.Actor.Avatars.').join(', ')
42 } 42 }
43} 43}
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 5485b72ec..e077cbf73 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -38,6 +38,8 @@ describe('Test video comments', function () {
38 await setDefaultAccountAvatar(server) 38 await setDefaultAccountAvatar(server)
39 39
40 userAccessTokenServer1 = await server.users.generateUserAndToken('user1') 40 userAccessTokenServer1 = await server.users.generateUserAndToken('user1')
41 await setDefaultChannelAvatar(server, 'user1_channel')
42 await setDefaultAccountAvatar(server, userAccessTokenServer1)
41 43
42 command = server.comments 44 command = server.comments
43 }) 45 })
@@ -240,9 +242,26 @@ describe('Test video comments', function () {
240 describe('All instance comments', function () { 242 describe('All instance comments', function () {
241 243
242 it('Should list instance comments as admin', async function () { 244 it('Should list instance comments as admin', async function () {
243 const { data } = await command.listForAdmin({ start: 0, count: 1 }) 245 {
246 const { data, total } = await command.listForAdmin({ start: 0, count: 1 })
244 247
245 expect(data[0].text).to.equal('my second answer to thread 4') 248 expect(total).to.equal(7)
249 expect(data).to.have.lengthOf(1)
250 expect(data[0].text).to.equal('my second answer to thread 4')
251 expect(data[0].account.name).to.equal('root')
252 expect(data[0].account.displayName).to.equal('root')
253 expect(data[0].account.avatars).to.have.lengthOf(2)
254 }
255
256 {
257 const { data, total } = await command.listForAdmin({ start: 1, count: 2 })
258
259 expect(total).to.equal(7)
260 expect(data).to.have.lengthOf(2)
261
262 expect(data[0].account.avatars).to.have.lengthOf(2)
263 expect(data[1].account.avatars).to.have.lengthOf(2)
264 }
246 }) 265 })
247 266
248 it('Should filter instance comments by isLocal', async function () { 267 it('Should filter instance comments by isLocal', async function () {