From feacbbff74d14d2c48e457acf6f1f9a6e3a84196 Mon Sep 17 00:00:00 2001 From: Erwan Martin Date: Wed, 27 Sep 2023 16:17:52 +0000 Subject: [PATCH] fix(caldav): do not update dates of tasks when repositioning them (#1605) When a task is updated, the position of the tasks of the whole project/bucket are updated. This leads to column "updated" of model Task to be updated quite often. However, that column is used for the ETag field of CALDAV. Thus, changing a task marks all the other tasks as updated, which prevents clients from synchronizing their edited tasks. Co-authored-by: Erwan Martin Reviewed-on: https://kolaente.dev/vikunja/api/pulls/1605 Co-authored-by: Erwan Martin Co-committed-by: Erwan Martin --- pkg/models/tasks.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 9b359878452..61242b9694a 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -1081,8 +1081,13 @@ func recalculateTaskKanbanPositions(s *xorm.Session, bucketID int64) (err error) currentPosition := maxPosition / float64(len(allTasks)) * (float64(i + 1)) + // Here we use "NoAutoTime() to prevent the ORM from updating column "updated" automatically. + // Otherwise, this signals to CalDAV clients that the task has changed, which is not the case. + // Consequence: when synchronizing a list of tasks, the first one immediately changes the date of all the + // following ones from the same batch, which are then unable to be updated. _, err = s.Cols("kanban_position"). Where("id = ?", task.ID). + NoAutoTime(). Update(&Task{KanbanPosition: currentPosition}) if err != nil { return @@ -1109,8 +1114,13 @@ func recalculateTaskPositions(s *xorm.Session, projectID int64) (err error) { currentPosition := maxPosition / float64(len(allTasks)) * (float64(i + 1)) + // Here we use "NoAutoTime() to prevent the ORM from updating column "updated" automatically. + // Otherwise, this signals to CalDAV clients that the task has changed, which is not the case. + // Consequence: when synchronizing a list of tasks, the first one immediately changes the date of all the + // following ones from the same batch, which are then unable to be updated. _, err = s.Cols("position"). Where("id = ?", task.ID). + NoAutoTime(). Update(&Task{Position: currentPosition}) if err != nil { return