Skip to content

Commit

Permalink
fix not available pictures uses storage
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Dec 12, 2023
1 parent f8c21ec commit 5a58743
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.benmanes.caffeine.cache.Cache;
import jakarta.annotation.Resource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Position;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class PictureServiceImpl extends ServiceImpl<PictureMapper, Picture> impl
private PictureMapper pictureMapper;


@Getter
private boolean allowSaveToDatabase = true;

// allowSaveToDatabase 是否允许上传图片写入数据库
Expand All @@ -68,10 +70,6 @@ public Cache<String, Picture> getWaitSavePictureCache() {
return waitSavePictureCache;
}

public boolean isAllowSaveToDatabase() {
return allowSaveToDatabase;
}

@Override
public Picture getPicture(String pid) {
Picture picture = pictureCache.getIfPresent(pid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public long getUsedStorage(long uid) {
Set<UserPicture> pictures = getUserPictures(uid);
long usedStorage = 0;
for (UserPicture picture : pictures) {
Picture pictureQuery = new Picture();
pictureQuery.setPid(picture.getPid());
Picture p = pictureMapper.selectOne(new QueryWrapper<>(pictureQuery));
if(p!=null)
if (!picture.getAvailable()) {
continue;
}
Picture p = pictureMapper.selectById(picture.getId());
if(p!=null) {
usedStorage += p.getSize();
}
}
return usedStorage;
}
Expand Down

0 comments on commit 5a58743

Please sign in to comment.