TASK:预签名缓存;

This commit is contained in:
shahaibo
2023-10-11 14:53:38 +08:00
parent 9e2f4f75c1
commit e5beab268c
9 changed files with 79 additions and 28 deletions

View File

@@ -403,4 +403,49 @@ public final class LocalCacheUtils {
return null;
}
/**
* 预签名URL缓存
*/
private static LoadingCache<String, String> presignedUrlCache = CacheBuilder.newBuilder()
.concurrencyLevel(10)
.expireAfterWrite((24 * 60 - 1), TimeUnit.MINUTES)
.initialCapacity(100)
.maximumSize(10000)
.recordStats()
.build(new CacheLoader<String, String>() {
@Override
public String load(String key) throws Exception {
return "null";
}
});
/**
* 添加预签名URL到缓存
*
* @param key URL的唯一标识
* @param value 预签名URL
*/
public static void setPresignedUrlCache(String key, String value) {
presignedUrlCache.put(key, value);
}
/**
* 获取预签名URL
*
* @param key URL的唯一标识
* @return 预签名URL如果不存在则返回null
*/
public static String getPresignedUrlCache(String key) {
try {
String value = presignedUrlCache.get(key);
if ("null".equals(value)) {
return null;
}
return value;
} catch (ExecutionException e) {
log.error("getPresignedUrlCache方法错误", e);
}
return null;
}
}

View File

@@ -370,13 +370,19 @@ public class MinioUtil {
}
public String getPresignedUrl(String path, int expiry) {
if (!path.contains("/")) {
throw new BusinessException("The path is error!");
if (LocalCacheUtils.getPresignedUrlCache(path) != null) {
return LocalCacheUtils.getPresignedUrlCache(path);
}else {
if (!path.contains("/")) {
throw new BusinessException("The path is error!");
}
int index = path.indexOf("/");
String bucketName = path.substring(0, index);
String fileName = path.substring(index + 1);
String presignedUrl = getPresignedUrl(bucketName, fileName, expiry);
LocalCacheUtils.setPresignedUrlCache(path, presignedUrl);
return presignedUrl;
}
int index = path.indexOf("/");
String bucketName = path.substring(0, index);
String fileName = path.substring(index + 1);
return getPresignedUrl(bucketName, fileName, expiry);
}
/**

View File

@@ -206,7 +206,7 @@ public class ChatRobotServiceImpl implements ChatRobotService {
if (!CollectionUtils.isEmpty(libraryList)) {
chatRobotLibraryVO.setId(libraryList.get(0).getId());
}
String aidaSysImage = minioUtil.getPresignedUrl("aida-sys-image", "images/" + array.getString(i), 10);
String aidaSysImage = minioUtil.getPresignedUrl("aida-sys-image", "images/" + array.getString(i), 24 * 60);
chatRobotLibraryVO.setUrl(bucketName + "/" + path);
chatRobotLibraryVO.setPresignedUrl(aidaSysImage);
chatRobotLibraryVOList.add(chatRobotLibraryVO);

View File

@@ -88,7 +88,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
saveOne(collectionElement);
CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class);
collectionElementVO.setMinIOPath(collectionElementVO.getUrl());
collectionElementVO.setUrl(minioUtil.getPresignedUrl(collectionElementVO.getUrl(), 480));
collectionElementVO.setUrl(minioUtil.getPresignedUrl(collectionElementVO.getUrl(), 24 * 60));
collectionElementVO.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
return collectionElementVO;
}

View File

@@ -80,7 +80,7 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
CollectionElement byId = collectionElementService.getById(response.getMoodTemplateId());
if (Objects.nonNull(byId)) {
response.setMoodTemplateName(byId.getName());
response.setMoodTemplateUrl(minioUtil.getPresignedUrl(byId.getUrl(), 10));
response.setMoodTemplateUrl(minioUtil.getPresignedUrl(byId.getUrl(), 24 * 60));
}
}
Map<String,List<CollectionElement>> maps = collectionElements
@@ -93,21 +93,21 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
case MOOD_BOARD:
response.setMoodBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 24 * 60));
}));
break;
case PRINT_BOARD:
response.setPrintBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
d.setIsPin(o.getHasPin());
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 24 * 60));
}));
break;
case SKETCH_BOARD:
response.setSketchBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d) ->{
d.setIsPin(o.getHasPin());
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 24 * 60));
}));
break;
case COLOR_BOARD:

View File

@@ -483,7 +483,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
String designUrl = designPythonOutfit.getDesignUrl();
if (!StringUtils.isEmpty(designUrl) && designUrl.contains("/")) {
int firstIndex = designUrl.indexOf("/");
designCollectionItemVO.setDesignOutfitUrl(minIoUtil.getPresignedUrl(designUrl.substring(0,firstIndex), designUrl.substring(firstIndex+1), 5));
designCollectionItemVO.setDesignOutfitUrl(minIoUtil.getPresignedUrl(designUrl.substring(0,firstIndex), designUrl.substring(firstIndex+1), 24 * 60));
}
//response
designCollectionItems.add(designCollectionItemVO);

View File

@@ -139,7 +139,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library,QueryLibraryPageVO.class);
libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName());
libraryPageVO.setMinIOPath(library.getUrl());
libraryPageVO.setUrl(minioUtil.getPresignedUrl(library.getUrl(),480));
libraryPageVO.setUrl(minioUtil.getPresignedUrl(library.getUrl(),24 * 60));
if(finalMap != null && finalMap.containsKey(library.getId())){
libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId()));
}
@@ -182,7 +182,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
Library library = resolveData(libraryUploadDTO, userInfo, newFilePath);
LibraryUpdateVo libraryUpdateVo = CopyUtil.copyObject(library, LibraryUpdateVo.class);
libraryUpdateVo.setMinIOPath(libraryUpdateVo.getUrl());
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(newFilePath, 480));
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(newFilePath, 24 * 60));
return libraryUpdateVo;
}else if (libraryUploadDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
bucketName = "aida-sys-image";
@@ -192,7 +192,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
Library library = resolveData(libraryUploadDTO, userInfo, newFilePath);
LibraryUpdateVo libraryUpdateVo = CopyUtil.copyObject(library, LibraryUpdateVo.class);
libraryUpdateVo.setMinIOPath(libraryUpdateVo.getUrl());
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(newFilePath, 480));
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(newFilePath, 24 * 60));
return libraryUpdateVo;
}else {
throw new BusinessException("unknown modelType");
@@ -203,7 +203,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
Library library = resolveData(libraryUploadDTO, userInfo, filePath);
LibraryUpdateVo libraryUpdateVo = CopyUtil.copyObject(library, LibraryUpdateVo.class);
libraryUpdateVo.setMinIOPath(libraryUpdateVo.getUrl());
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(libraryUpdateVo.getUrl(), 480));
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(libraryUpdateVo.getUrl(), 24 * 60));
return libraryUpdateVo;
}
}

View File

@@ -111,7 +111,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
int index = o.getUrl().lastIndexOf("/");
o.setPictureName(o.getUrl().substring(index + 1));
}
o.setDesignOutfitUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
o.setDesignOutfitUrl(minioUtil.getPresignedUrl(o.getUrl(), 24 * 60));
QueryWrapper<TDesignPythonOutfit> qw = new QueryWrapper<>();
qw.lambda().eq(TDesignPythonOutfit::getDesignItemId, o.getDesignItemId());
List<TDesignPythonOutfit> tDesignPythonOutfits = designPythonOutfitMapper.selectList(qw);

View File

@@ -160,16 +160,16 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
WorkspaceVO workspaceVO = CopyUtil.copyObject(o, WorkspaceVO.class);
if (o.getMannequinFemaleId() != null) {
if (o.getMannequinFemaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinFemaleId()).getUrl(), 24 * 60));
}else if (o.getMannequinFemaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinFemaleId()).getUrl(), 24 * 60));
}
}
if (o.getMannequinMaleId() != null) {
if (o.getMannequinMaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinMaleId()).getUrl(), 24 * 60));
}else if (o.getMannequinMaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinMaleId()).getUrl(), 24 * 60));
}
}
return workspaceVO;
@@ -184,16 +184,16 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
WorkspaceVO workspaceVO = CopyUtil.copyObject(o, WorkspaceVO.class);
if (o.getMannequinFemaleId() != null) {
if (o.getMannequinFemaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinFemaleId()).getUrl(), 24 * 60));
}else if (o.getMannequinFemaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinFemaleId()).getUrl(), 24 * 60));
}
}
if (o.getMannequinMaleId() != null) {
if (o.getMannequinMaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinMaleId()).getUrl(), 24 * 60));
}else if (o.getMannequinMaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinMaleId()).getUrl(), 24 * 60));
}
}
return workspaceVO;
@@ -253,7 +253,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
ModelVO modelVO = new ModelVO();
modelVO.setId(library.getId());
modelVO.setUrl(library.getUrl());
modelVO.setPresignedUrl(minioUtil.getPresignedUrl(library.getUrl(), 480));
modelVO.setPresignedUrl(minioUtil.getPresignedUrl(library.getUrl(), 24 * 60));
modelVOList.add(modelVO);
}
ModelsVO vo = new ModelsVO();
@@ -273,7 +273,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
ModelVO modelVO = new ModelVO();
modelVO.setId(sysFile.getId());
modelVO.setUrl(sysFile.getUrl());
modelVO.setPresignedUrl(minioUtil.getPresignedUrl(sysFile.getUrl(), 480));
modelVO.setPresignedUrl(minioUtil.getPresignedUrl(sysFile.getUrl(), 24 * 60));
modelVOList.add(modelVO);
}
ModelsVO vo = new ModelsVO();