MCPcopy Create free account
hub / github.com/53AI/53AIHub / BatchUpdateLibrarySort

Function BatchUpdateLibrarySort

api/model/library.go:420–443  ·  view source on GitHub ↗

BatchUpdateLibrarySort 批量更新知识库排序

(eid int64, sortList []struct {
	ID   int64 `json:"id" binding:"required"`
	Sort int64 `json:"sort" binding:"required"`
})

Source from the content-addressed store, hash-verified

418
419// BatchUpdateLibrarySort 批量更新知识库排序
420func BatchUpdateLibrarySort(eid int64, sortList []struct {
421 ID int64 `json:"id" binding:"required"`
422 Sort int64 `json:"sort" binding:"required"`
423}) error {
424 tx := DB.Begin()
425 defer func() {
426 if r := recover(); r != nil {
427 tx.Rollback()
428 }
429 }()
430
431 for _, item := range sortList {
432 if err := tx.Model(&Library{}).Where("eid = ? AND id = ?", eid, item.ID).Update("sort", item.Sort).Error; err != nil {
433 tx.Rollback()
434 return err
435 }
436 }
437
438 if err := tx.Commit().Error; err != nil {
439 return err
440 }
441 invalidateLibraryCache(eid)
442 return nil
443}
444
445func GetRecentlyLibraries(eid int64, limit int) ([]Library, error) {
446 libraries, err := GetLibrariesByEidCached(eid)

Callers

nothing calls this directly

Calls 2

invalidateLibraryCacheFunction · 0.70
UpdateMethod · 0.65

Tested by

no test coverage detected