-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复cache.cfg丢时缓存映射错误 #2527
修复cache.cfg丢时缓存映射错误 #2527
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2527 +/- ##
=======================================
Coverage 77.32% 77.33%
=======================================
Files 420 420
Lines 22457 22460 +3
Branches 6325 6346 +21
=======================================
+ Hits 17365 17369 +4
- Misses 3818 3819 +1
+ Partials 1274 1272 -2 ☔ View full report in Codecov by Sentry. |
This reverts commit e2b8d28.
src/rendering/caches/DiskCache.cpp
Outdated
@@ -73,6 +73,7 @@ DiskCache::DiskCache() { | |||
if (!cacheDir.empty()) { | |||
configPath = Directory::JoinPath(cacheDir, "cache.cfg"); | |||
cacheFolder = Directory::JoinPath(cacheDir, "files"); | |||
removeRedundancyCache(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removeRedundancyCache存在很多 readConfig里已经写过的重复代码,可以给 readConfig() 加个返回值,如果读取配置失败(不存在文件或者文件size为0)就返回false:然后判断返回值即可:
if (!readConfig()) { Directory::VisitFiles(cacheFolder, [&](const std::string& path, size_t) { remove(path.c_str()); }); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实这样更优雅我改改
src/rendering/caches/DiskCache.cpp
Outdated
@@ -73,7 +73,11 @@ DiskCache::DiskCache() { | |||
if (!cacheDir.empty()) { | |||
configPath = Directory::JoinPath(cacheDir, "cache.cfg"); | |||
cacheFolder = Directory::JoinPath(cacheDir, "files"); | |||
readConfig(); | |||
auto ret = readConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量命名要避免使用缩写ret,可以直接用if(!readConfig()),或者起个有明确含义的变量名
问题描述
近期我司产品有用户反馈发送的表情和预期不符.如发送一个哭的表情变为笑.
说明
缺陷 1
假设缓存关系如下:
http://hello.pag -> 1.bin
http://world.pag -> 2.bin
cache.cfg 被回收删除但是缓存文件依旧存在时,我们重启 app .我们调用readFile函数,传入 http://world.pag .
缺陷 2
调用saveConfig 时被强制中断,会导致cache.cfg 丢失.从而导致缓存错误
问题模拟复现
插入以下代码,在休眠期间强制停止