Don't create a list identifier by default

This commit is contained in:
kolaente 2020-12-18 13:07:34 +01:00
parent 969e467f48
commit ccfa019870
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -17,7 +17,6 @@
package models package models
import ( import (
"strings"
"time" "time"
"code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/files"
@ -447,43 +446,6 @@ func (l *List) CheckIsArchived() (err error) {
return nil return nil
} }
// GenerateListIdentifier generates a unique random list identifier based on the list title.
// If it is not able to find one, the list identifier will be empty.
func GenerateListIdentifier(l *List, sess *xorm.Engine) (err error) {
// The general idea here is to take the title and slice it into pieces, until we found a unique piece.
var exists = true
titleSlug := []rune(strings.ReplaceAll(strings.ToUpper(l.Title), " ", ""))
// We can save at most 10 characters in the db, so we need to ensure it has at most 10 characters
if len(titleSlug) > 10 {
titleSlug = titleSlug[0:9]
}
var i = 0
for exists {
// Prevent endless looping
if i == len(titleSlug) {
break
}
// Take a random part of the title slug, starting at the beginning
l.Identifier = string(titleSlug[i:])
exists, err = sess.
Where("identifier = ?", l.Identifier).
And("id != ?", l.ID).
Exist(&List{})
if err != nil {
return
}
i++
}
return nil
}
// CreateOrUpdateList updates a list or creates it if it doesn't exist // CreateOrUpdateList updates a list or creates it if it doesn't exist
func CreateOrUpdateList(list *List) (err error) { func CreateOrUpdateList(list *List) (err error) {
@ -509,14 +471,6 @@ func CreateOrUpdateList(list *List) (err error) {
} }
} }
// Generate a random list identifier base on the list title
if list.ID == 0 && list.Identifier == "" {
err = GenerateListIdentifier(list, x)
if err != nil {
return
}
}
if list.ID == 0 { if list.ID == 0 {
_, err = x.Insert(list) _, err = x.Insert(list)
metrics.UpdateCount(1, metrics.ListCountKey) metrics.UpdateCount(1, metrics.ListCountKey)