From de674b5a2c43478f078fabc931981b957988a53d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 18 Jun 2026 21:57:42 +0000 Subject: [PATCH] refactor(kanban): parameterize only the conflict clause of the upsert Shorten the comment and branch only on the ON CONFLICT / ON DUPLICATE KEY clause, keeping the shared INSERT in one place so it's easier to update. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01JK7JwuvjhcsNf5d5fUopeY --- pkg/models/kanban_task_bucket.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/models/kanban_task_bucket.go b/pkg/models/kanban_task_bucket.go index c49668bdf..90e48d70f 100644 --- a/pkg/models/kanban_task_bucket.go +++ b/pkg/models/kanban_task_bucket.go @@ -60,17 +60,15 @@ func (b *TaskBucket) CanUpdate(s *xorm.Session, a web.Auth) (bool, error) { } func (b *TaskBucket) upsert(s *xorm.Session) (err error) { - // A single native upsert keyed on the unique(task_id, project_view_id) - // index: it moves the task to the new bucket if the row exists and inserts - // it otherwise, atomically and without depending on the affected-row count - // (MySQL/MariaDB report 0 affected rows for an unchanged value). - query := "INSERT INTO task_buckets (task_id, project_view_id, bucket_id) VALUES (?, ?, ?) " + - "ON CONFLICT (task_id, project_view_id) DO UPDATE SET bucket_id = excluded.bucket_id" + // A native upsert moves the task in one atomic statement, without + // depending on the affected-row count (MySQL/MariaDB report 0 affected + // rows for an unchanged value). + onConflict := "ON CONFLICT (task_id, project_view_id) DO UPDATE SET bucket_id = excluded.bucket_id" if db.Type() == schemas.MYSQL { - query = "INSERT INTO task_buckets (task_id, project_view_id, bucket_id) VALUES (?, ?, ?) " + - "ON DUPLICATE KEY UPDATE bucket_id = VALUES(bucket_id)" + onConflict = "ON DUPLICATE KEY UPDATE bucket_id = VALUES(bucket_id)" } + query := "INSERT INTO task_buckets (task_id, project_view_id, bucket_id) VALUES (?, ?, ?) " + onConflict _, err = s.Exec(query, b.TaskID, b.ProjectViewID, b.BucketID) return }