feat(views): only update the bucket when necessary
This commit is contained in:
parent
f2a0d69670
commit
8ce476491e
@ -112,7 +112,8 @@ type Task struct {
|
|||||||
// A timestamp when this task was last updated. You cannot change this value.
|
// A timestamp when this task was last updated. You cannot change this value.
|
||||||
Updated time.Time `xorm:"updated not null" json:"updated"`
|
Updated time.Time `xorm:"updated not null" json:"updated"`
|
||||||
|
|
||||||
// Deprecated: use the id via the separate entity.
|
// The bucket id. Will only be populated when the task is accessed via a view with buckets.
|
||||||
|
// Can be used to move a task between buckets. In that case, the new bucket must be in the same view as the old one.
|
||||||
BucketID int64 `xorm:"bigint null" json:"bucket_id"`
|
BucketID int64 `xorm:"bigint null" json:"bucket_id"`
|
||||||
|
|
||||||
// The position of the task - any task project can be sorted as usual by this parameter.
|
// The position of the task - any task project can be sorted as usual by this parameter.
|
||||||
@ -620,17 +621,6 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkBucketAndTaskBelongToSameProject(fullTask *Task, bucket *Bucket) (err error) {
|
|
||||||
if fullTask.ProjectID != bucket.ProjectID {
|
|
||||||
return ErrBucketDoesNotBelongToProject{
|
|
||||||
ProjectID: fullTask.ProjectID,
|
|
||||||
BucketID: fullTask.BucketID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks if adding a new task would exceed the bucket limit
|
// Checks if adding a new task would exceed the bucket limit
|
||||||
func checkBucketLimit(s *xorm.Session, t *Task, bucket *Bucket) (err error) {
|
func checkBucketLimit(s *xorm.Session, t *Task, bucket *Bucket) (err error) {
|
||||||
if bucket.Limit > 0 {
|
if bucket.Limit > 0 {
|
||||||
@ -693,7 +683,12 @@ func setTaskBucket(s *xorm.Session, task *Task, originalTask *Task, view *Projec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there is a bucket set, make sure they belong to the same project as the task
|
// If there is a bucket set, make sure they belong to the same project as the task
|
||||||
err = checkBucketAndTaskBelongToSameProject(task, bucket)
|
if task.ProjectID != bucket.ProjectID {
|
||||||
|
return ErrBucketDoesNotBelongToProject{
|
||||||
|
ProjectID: task.ProjectID,
|
||||||
|
BucketID: bucket.ID,
|
||||||
|
}
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -918,15 +913,28 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, view := range views {
|
buckets := make(map[int64]*Bucket)
|
||||||
// bucket id mitgeben, dann den view zu dem bucket suchen und updaten wenn nötig
|
err = s.In("project_project_id",
|
||||||
|
builder.Select("id").
|
||||||
|
From("project_views").
|
||||||
|
Where(builder.Eq{"project_id": t.ProjectID}),
|
||||||
|
).
|
||||||
|
Find(&buckets)
|
||||||
|
|
||||||
|
for _, view := range views {
|
||||||
taskBucket := &TaskBucket{
|
taskBucket := &TaskBucket{
|
||||||
BucketID: t.BucketID,
|
|
||||||
TaskID: t.ID,
|
TaskID: t.ID,
|
||||||
ProjectViewID: view.ID,
|
ProjectViewID: view.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only update the bucket when the current view
|
||||||
|
if t.BucketID != 0 {
|
||||||
|
bucket, has := buckets[t.BucketID]
|
||||||
|
if has && bucket.ProjectViewID == view.ID {
|
||||||
|
taskBucket.BucketID = t.BucketID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = setTaskBucket(s, t, &ot, view, taskBucket)
|
err = setTaskBucket(s, t, &ot, view, taskBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user