mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-11 17:48:44 -05:00
fix: use MinPositionSpacing threshold in calculateNewPositionForTask (#2320)
calculateNewPositionForTask only checked for lowestPosition == 0 before triggering a full position recalculation. Extremely small position values (e.g. 3.16e-285) passed this check, causing new tasks to get meaningless positions via the index * 2^16 fallback, breaking sort order. Use the same < MinPositionSpacing threshold that createPositionsForTasksInView and the position update handler already use. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -303,7 +303,8 @@ func recalculateTaskPositionsForRepair(s *xorm.Session, view *ProjectView) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func calculateNewPositionForTask(s *xorm.Session, a web.Auth, t *Task, view *ProjectView) (*TaskPosition, error) {
|
func calculateNewPositionForTask(s *xorm.Session, a web.Auth, t *Task, view *ProjectView) (*TaskPosition, error) {
|
||||||
if t.Position == 0 {
|
position := t.Position
|
||||||
|
if position == 0 {
|
||||||
lowestPosition := &TaskPosition{}
|
lowestPosition := &TaskPosition{}
|
||||||
exists, err := s.Where("project_view_id = ?", view.ID).
|
exists, err := s.Where("project_view_id = ?", view.ID).
|
||||||
OrderBy("position asc").
|
OrderBy("position asc").
|
||||||
@@ -312,7 +313,7 @@ func calculateNewPositionForTask(s *xorm.Session, a web.Auth, t *Task, view *Pro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if exists {
|
if exists {
|
||||||
if lowestPosition.Position == 0 {
|
if lowestPosition.Position < MinPositionSpacing {
|
||||||
err = RecalculateTaskPositions(s, view, a)
|
err = RecalculateTaskPositions(s, view, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -327,14 +328,14 @@ func calculateNewPositionForTask(s *xorm.Session, a web.Auth, t *Task, view *Pro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Position = lowestPosition.Position / 2
|
position = lowestPosition.Position / 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &TaskPosition{
|
return &TaskPosition{
|
||||||
TaskID: t.ID,
|
TaskID: t.ID,
|
||||||
ProjectViewID: view.ID,
|
ProjectViewID: view.ID,
|
||||||
Position: calculateDefaultPosition(t.Index, t.Position),
|
Position: calculateDefaultPosition(t.Index, position),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user