]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix comments SQL pagination
authorChocobozzz <me@florianbigard.com>
Tue, 10 Jan 2023 08:16:33 +0000 (09:16 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 10 Jan 2023 08:17:23 +0000 (09:17 +0100)
server/models/video/sql/comment/video-comment-list-query-builder.ts
server/models/video/sql/comment/video-comment-table-attributes.ts
server/tests/api/videos/video-comments.ts

index f3f6910e1a1243646ad722720b94cde6576b2b62..49b41b6d818496c70ee99c183fb01c7e7215f139 100644 (file)
@@ -87,8 +87,7 @@ export class VideoCommentListQueryBuilder extends AbstractRunQuery {
     this.query = `${this.select} ` +
       `FROM (${this.innerQuery}) AS "VideoCommentModel" ` +
       `${this.joins} ` +
-      `${this.getOrder()} ` +
-      `${this.getLimit()}`
+      `${this.getOrder()}`
   }
 
   private buildInnerListQuery () {
@@ -375,14 +374,6 @@ export class VideoCommentListQueryBuilder extends AbstractRunQuery {
     return 'ORDER BY ' + orders.map(o => `"${o[0]}" ${o[1]}`).join(', ')
   }
 
-  private getLimit () {
-    if (!this.options.count) return ''
-
-    this.replacements.limit = this.options.count
-
-    return `LIMIT :limit `
-  }
-
   private getInnerLimit () {
     if (!this.options.count) return ''
 
index 10e635e41f88d1d9e427acc0fb19a3c086564334..87f8750c17d9220bd80373b3fcb5cc6bb9a99947 100644 (file)
@@ -38,6 +38,6 @@ export class VideoCommentTableAttributes {
 
   @Memoize()
   getAvatarAttributes () {
-    return ActorImageModel.getSQLAttributes('Account->Actor->Avatars', 'Account.Actor.Avatars.id').join(', ')
+    return ActorImageModel.getSQLAttributes('Account->Actor->Avatars', 'Account.Actor.Avatars.').join(', ')
   }
 }
index 5485b72ec4519c2aaf125d8b6ff0a9a41df78584..e077cbf73569c2653012a9c1b13165fe7a736f27 100644 (file)
@@ -38,6 +38,8 @@ describe('Test video comments', function () {
     await setDefaultAccountAvatar(server)
 
     userAccessTokenServer1 = await server.users.generateUserAndToken('user1')
+    await setDefaultChannelAvatar(server, 'user1_channel')
+    await setDefaultAccountAvatar(server, userAccessTokenServer1)
 
     command = server.comments
   })
@@ -240,9 +242,26 @@ describe('Test video comments', function () {
   describe('All instance comments', function () {
 
     it('Should list instance comments as admin', async function () {
-      const { data } = await command.listForAdmin({ start: 0, count: 1 })
+      {
+        const { data, total } = await command.listForAdmin({ start: 0, count: 1 })
 
-      expect(data[0].text).to.equal('my second answer to thread 4')
+        expect(total).to.equal(7)
+        expect(data).to.have.lengthOf(1)
+        expect(data[0].text).to.equal('my second answer to thread 4')
+        expect(data[0].account.name).to.equal('root')
+        expect(data[0].account.displayName).to.equal('root')
+        expect(data[0].account.avatars).to.have.lengthOf(2)
+      }
+
+      {
+        const { data, total } = await command.listForAdmin({ start: 1, count: 2 })
+
+        expect(total).to.equal(7)
+        expect(data).to.have.lengthOf(2)
+
+        expect(data[0].account.avatars).to.have.lengthOf(2)
+        expect(data[1].account.avatars).to.have.lengthOf(2)
+      }
     })
 
     it('Should filter instance comments by isLocal', async function () {