fix: deadlock while creating default user in SQLite
This commit is contained in:
2
assets
2
assets
Submodule assets updated: ac3af6097f...0deacc2d4d
@@ -102,12 +102,16 @@ func (folder *Folder) GetChildFiles() ([]File, error) {
|
|||||||
// GetFilesByIDs 根据文件ID批量获取文件,
|
// GetFilesByIDs 根据文件ID批量获取文件,
|
||||||
// UID为0表示忽略用户,只根据文件ID检索
|
// UID为0表示忽略用户,只根据文件ID检索
|
||||||
func GetFilesByIDs(ids []uint, uid uint) ([]File, error) {
|
func GetFilesByIDs(ids []uint, uid uint) ([]File, error) {
|
||||||
|
return GetFilesByIDsFromTX(DB, ids, uid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFilesByIDsFromTX(tx *gorm.DB, ids []uint, uid uint) ([]File, error) {
|
||||||
var files []File
|
var files []File
|
||||||
var result *gorm.DB
|
var result *gorm.DB
|
||||||
if uid == 0 {
|
if uid == 0 {
|
||||||
result = DB.Where("id in (?)", ids).Find(&files)
|
result = tx.Where("id in (?)", ids).Find(&files)
|
||||||
} else {
|
} else {
|
||||||
result = DB.Where("id in (?) AND user_id = ?", ids, uid).Find(&files)
|
result = tx.Where("id in (?) AND user_id = ?", ids, uid).Find(&files)
|
||||||
}
|
}
|
||||||
return files, result.Error
|
return files, result.Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ func IsTrueVal(val string) bool {
|
|||||||
|
|
||||||
// GetSettingByName 用 Name 获取设置值
|
// GetSettingByName 用 Name 获取设置值
|
||||||
func GetSettingByName(name string) string {
|
func GetSettingByName(name string) string {
|
||||||
|
return GetSettingByNameFromTx(DB, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSettingByNameFromTx 用 Name 获取设置值,使用事务
|
||||||
|
func GetSettingByNameFromTx(tx *gorm.DB, name string) string {
|
||||||
var setting Setting
|
var setting Setting
|
||||||
|
|
||||||
// 优先从缓存中查找
|
// 优先从缓存中查找
|
||||||
@@ -32,13 +37,18 @@ func GetSettingByName(name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 尝试数据库中查找
|
// 尝试数据库中查找
|
||||||
if DB != nil {
|
if tx == nil {
|
||||||
result := DB.Where("name = ?", name).First(&setting)
|
tx = DB
|
||||||
|
if tx == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result := tx.Where("name = ?", name).First(&setting)
|
||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
_ = cache.Set(cacheKey, setting.Value, -1)
|
_ = cache.Set(cacheKey, setting.Value, -1)
|
||||||
return setting.Value
|
return setting.Value
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user