fix: Improve texture upload handling and caching logic
- Simplified caching logic by removing unnecessary nil check before setting cache. - Enhanced error handling in texture upload process to return the original texture object if fetching the uploader information fails or returns nil.
This commit is contained in:
@@ -87,9 +87,7 @@ func (s *textureService) GetByID(ctx context.Context, id int64) (*model.Texture,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 存入缓存(异步)
|
// 存入缓存(异步)
|
||||||
if texture2 != nil {
|
|
||||||
s.cache.SetAsync(context.Background(), cacheKey, texture2, s.cache.Policy.TextureTTL)
|
s.cache.SetAsync(context.Background(), cacheKey, texture2, s.cache.Policy.TextureTTL)
|
||||||
}
|
|
||||||
|
|
||||||
return texture2, nil
|
return texture2, nil
|
||||||
}
|
}
|
||||||
@@ -382,7 +380,16 @@ func (s *textureService) UploadTexture(ctx context.Context, uploaderID int64, na
|
|||||||
s.cacheInv.BatchInvalidate(ctx, fmt.Sprintf("texture:user:%d:*", uploaderID))
|
s.cacheInv.BatchInvalidate(ctx, fmt.Sprintf("texture:user:%d:*", uploaderID))
|
||||||
|
|
||||||
// 重新查询以预加载 Uploader 关联
|
// 重新查询以预加载 Uploader 关联
|
||||||
return s.textureRepo.FindByID(ctx, texture.ID)
|
textureWithUploader, err := s.textureRepo.FindByID(ctx, texture.ID)
|
||||||
|
if err != nil {
|
||||||
|
// 如果查询失败,返回原始创建的 texture 对象(虽然可能没有 Uploader 信息)
|
||||||
|
return texture, nil
|
||||||
|
}
|
||||||
|
if textureWithUploader == nil {
|
||||||
|
// 如果查询返回 nil(极端情况,如数据库复制延迟),返回原始创建的 texture 对象
|
||||||
|
return texture, nil
|
||||||
|
}
|
||||||
|
return textureWithUploader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseTextureTypeInternal 解析材质类型
|
// parseTextureTypeInternal 解析材质类型
|
||||||
|
|||||||
Reference in New Issue
Block a user