fix(task): only load first comments page when loading comments with task

Resolves
https://community.vikunja.io/t/task-comment-pagination-in-1-0-0-rc1/3988
This commit is contained in:
kolaente 2025-08-31 21:58:46 +02:00
parent 0262ab7d9e
commit ed04638726
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
2 changed files with 25 additions and 1 deletions

View File

@ -255,7 +255,9 @@ func (tc *TaskComment) ReadAll(s *xorm.Session, auth web.Auth, search string, pa
}
func addCommentsToTasks(s *xorm.Session, taskIDs []int64, taskMap map[int64]*Task) (err error) {
comments, _, _, err := getAllCommentsForTasksWithoutPermissionCheck(s, taskIDs, "", 0, 50)
// Only fetch the first page of comments when expanding tasks to avoid
// loading all comments for tasks with many comments.
comments, _, _, err := getAllCommentsForTasksWithoutPermissionCheck(s, taskIDs, "", 1, 50)
if err != nil {
return err
}

View File

@ -17,6 +17,7 @@
package models
import (
"fmt"
"testing"
"code.vikunja.io/api/pkg/db"
@ -270,3 +271,24 @@ func TestTaskComment_ReadAll(t *testing.T) {
assert.Equal(t, int64(15), resultComment[0].ID)
})
}
func TestAddCommentsToTasksLimit(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
taskID := int64(1)
// Add a bunch of comments to exceed the pagination limit
for i := 0; i < 60; i++ {
_, err := s.Insert(&TaskComment{Comment: fmt.Sprintf("bulk %d", i), TaskID: taskID, AuthorID: 1})
require.NoError(t, err)
}
task := &Task{ID: taskID}
taskMap := map[int64]*Task{taskID: task}
err := addCommentsToTasks(s, []int64{taskID}, taskMap)
require.NoError(t, err)
assert.Len(t, task.Comments, 50)
}