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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JK7JwuvjhcsNf5d5fUopeY
This commit is contained in:
Claude 2026-06-18 21:57:42 +00:00
parent 693fbb52b5
commit de674b5a2c
No known key found for this signature in database
1 changed files with 6 additions and 8 deletions

View File

@ -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
}