MCPcopy
hub / github.com/gotify/server / fillMissingSortKeys

Function fillMissingSortKeys

database/database.go:100–131  ·  view source on GitHub ↗
(db *gorm.DB)

Source from the content-addressed store, hash-verified

98}
99
100func fillMissingSortKeys(db *gorm.DB) error {
101 missingSort := int64(0)
102 if err := db.Model(new(model.Application)).Where("sort_key IS NULL OR sort_key = ''").Count(&missingSort).Error; err != nil {
103 return err
104 }
105
106 if missingSort == 0 {
107 return nil
108 }
109
110 var apps []*model.Application
111 if err := db.Order("user_id, sort_key, id ASC").Find(&apps).Error; err != nil && err != gorm.ErrRecordNotFound {
112 return err
113 }
114 fmt.Println("Migrating", len(apps), "application sort keys")
115
116 sortKey := ""
117 currentUser := uint(math.MaxUint)
118 var err error
119 for _, app := range apps {
120 if currentUser != app.UserID {
121 sortKey = ""
122 currentUser = app.UserID
123 }
124 sortKey, err = fracdex.KeyBetween(sortKey, "")
125 if err != nil {
126 return err
127 }
128 app.SortKey = sortKey
129 }
130 return db.Save(apps).Error
131}
132
133func createDirectoryIfSqlite(dialect, connection string) {
134 if dialect == "sqlite3" {

Callers 1

TestMigrateSortKeyFunction · 0.85

Calls 2

KeyBetweenFunction · 0.92
SaveMethod · 0.65

Tested by 1

TestMigrateSortKeyFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…