mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix: cache value assertion panic if the cache adapter is not in-memory for soft time feature of package gdb; improve converting performance for gconv.Scan (#3351)
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
// Package gdb provides ORM features for popular relationship databases.
|
||||
//
|
||||
// TODO use context.Context as required parameter for all DB operations.
|
||||
package gdb
|
||||
|
||||
import (
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
)
|
||||
|
||||
// CacheOption is options for model cache control in query.
|
||||
@ -67,7 +66,6 @@ func (m *Model) getSelectResultFromCache(ctx context.Context, sql string, args .
|
||||
return
|
||||
}
|
||||
var (
|
||||
ok bool
|
||||
cacheItem *selectCacheItem
|
||||
cacheKey = m.makeSelectCacheKey(sql, args...)
|
||||
cacheObj = m.db.GetCache()
|
||||
@ -82,12 +80,7 @@ func (m *Model) getSelectResultFromCache(ctx context.Context, sql string, args .
|
||||
}
|
||||
}()
|
||||
if v, _ := cacheObj.Get(ctx, cacheKey); !v.IsNil() {
|
||||
if cacheItem, ok = v.Val().(*selectCacheItem); ok {
|
||||
// In-memory cache.
|
||||
return cacheItem.Result, nil
|
||||
}
|
||||
// Other cache, it needs conversion.
|
||||
if err = json.UnmarshalUseNumber(v.Bytes(), &cacheItem); err != nil {
|
||||
if err = v.Scan(&cacheItem); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cacheItem.Result, nil
|
||||
|
||||
@ -219,7 +219,10 @@ func (m *softTimeMaintainer) getSoftFieldNameAndType(
|
||||
intlog.Error(ctx, err)
|
||||
}
|
||||
if result != nil {
|
||||
var cacheItem = result.Val().(getSoftFieldNameAndTypeCacheItem)
|
||||
var cacheItem getSoftFieldNameAndTypeCacheItem
|
||||
if err = result.Scan(&cacheItem); err != nil {
|
||||
return "", ""
|
||||
}
|
||||
fieldName = cacheItem.FieldName
|
||||
fieldType = cacheItem.FieldType
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user