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:
parent
0262ab7d9e
commit
ed04638726
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue