-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Fix rename of default disk cache directory #2412
Conversation
Codecov Report
@@ Coverage Diff @@
## 5.x #2412 +/- ##
==========================================
+ Coverage 68.83% 68.93% +0.09%
==========================================
Files 47 47
Lines 6649 6669 +20
==========================================
+ Hits 4577 4597 +20
Misses 2072 2072
Continue to review full report at Codecov.
|
@zhongwuzw You can still use the default path as you want. Just keep the old cache folder without any issue. See #2299 SDImageCacheConfig.defaultCacheConfig.namespacePrefix = @"com.hackemist.SDWebImageCache."; So I don't think we need to do anything like movement, each time you call init method for |
@dreampiggy , nope, we can't expect users to know everything internal. Many users would just use one shot |
@@ -47,13 +47,13 @@ | |||
} | |||
} | |||
if (!image) { | |||
SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; | |||
SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; |
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.
This change is adoptable. Because this may shadow the options
arg from the input arg. But this is not related to this PR, create another instead...
For each PR, it should contains the most related change for the feature/bugfix. Don't try to bundle something unrelated to a single PR, because this will make it hard to review, and may cause issue if we want to revert.
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.
I agree with this approach as a generic rule of thumb, but I think we can let this one slip :)
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.
@dreampiggy 👌 I just think it's trivial, so I do not create a separate PR
. I'll be careful next time. 😂
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.
Looks good to me.
@zhongwuzw This change, should be already in the migration guide. For 4.x user, they should read it before upgrating, because some changes are totally break change, which not designed to be compatible. And some change may also change the semantic of same API naming. For example, the method in |
@dreampiggy this is not the case of changing some APIs - which indeed are subject to reading the migration guide and updating the consumer code. |
Yeah, when we develop a product, we need treat users as foolish (No discriminate, it's just the truth for product 😂 ), just like #2409 , we can't expect user know everything. We just try our best to let users go to the right path, decrease mistakes. If we think users needs to know everything, maybe we don't need to fix bug anymore. Let's user do it. 😂 |
@bpoplauschi I add one chapter about the important behavior changs outside API chanegs in the Migration-Guide-Notable-Behavior-Changes. Because this changes, will been called each time you create If you still agree that this is big issue and need we do so, this code should not been placed in the |
|
@dreampiggy The path you listed in Migration Guide is wrong. The correct relative path is I think it's up to how you understand the manager, if you think all related operation should put into |
@zhongwuzw No. for example we have a custom disk cache implementation, and put new images in that But however, our disk cache does not use MD5 hash for key-mapping. It may be a case that a cache key may be hashed to the same value, which should been a cache miss in our hash check, but it accidentilly hit the original files from 4.x folder. Which will cause issue. 4.x && 5.x's |
@dreampiggy If any user changed |
@zhongwuzw If you still need to do a disk cache migration. My consideration is that this code should not been placed into For SDWebImage, by default it always use Put any disk reading & writing code in |
@dreampiggy Yeah, I can, what's your opinion about @bpoplauschi 's proposal, we can use |
@zhongwuzw Create a new protocol, just for a compatible method, is overcome. Actually people we use custom disk cache, may not use the default cache prefix because this will cause issue. (Like we use a separate prefix). So, maybe we can reach a consensus , some adddtional changes should be provided:
|
@dreampiggy @bpoplauschi The reasons why I put only disk related operation to
What's your guys think about? 🤔 |
SDWebImage/SDImageCache.m
Outdated
@@ -86,7 +86,7 @@ - (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns | |||
|
|||
NSAssert([config.diskCacheClass conformsToProtocol:@protocol(SDDiskCache)], @"Custom disk cache class must conform to `SDDiskCache` protocol"); | |||
_diskCache = [[config.diskCacheClass alloc] initWithCachePath:_diskCachePath config:_config]; | |||
[self moveOldDefaultDiskPathOfFilesToNewDefaultDiskPath]; | |||
[self migrateCacheDiskDirectory]; |
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.
...emmm. Am I miss something ?
I means, move all code, into [SDDiskCache initWithCachePath:config:]
method. Don't need to modify any code in SDImageCache.m
, this method should not be visible in header files as well.
During init method of SDDiskCache
, use dispatch_once + global queue to only move once.
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.
@dreampiggy emm, I know you opinion, so I put the reasons in here. I can explain my thoughts further.
Why I put the default cache path in SDImageCache
is we generate the default cache path in SDImageCache
, right? Let's see how we generate in SDImageCache
:
// class of SDImageCache
- (instancetype)init {
return [self initWithNamespace:@"default"];
}
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns {
NSString *path = [self makeDiskCachePath:ns]; // first component disk cache path
return [self initWithNamespace:ns diskCacheDirectory:path];
}
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns
diskCacheDirectory:(nonnull NSString *)directory
config:(nullable SDImageCacheConfig *)config {
if ((self = [super init])) {
NSString *namespacePrefix = config.namespacePrefix;
if (!namespacePrefix) {
namespacePrefix = @"";
}
NSString *fullNamespace = [namespacePrefix stringByAppendingString:ns];
// Init the disk cache
if (directory != nil) {
_diskCachePath = [directory stringByAppendingPathComponent:fullNamespace];
} else {
NSString *path = [self makeDiskCachePath:ns];
_diskCachePath = path;
}
return self;
}
We combine many components to generate default cache disk path. The SDDiskCache
is just a class that do disk operations, like access, delete, move, right? other words, it doesn't need to know what's the disk path it is, its only job is do disk operation, I think compare old and new disk path is not what it should do. If you still think we should put all these things to SDDiskCache
, should we need to hard code the default path? or extract the methods of default cache path related methods into a single class to let both SDImageCache
and SDDiskCache
access it?
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.
@zhongwuzw take a look at #2417, I think the approach from @dreampiggy is simpler.
But I would not be so picky in choosing the approach :) You guys should decide
I think calling private methods is just a bad practice (Apple discourages this) and error prone. |
I just merged #2417 so closing this PR. Thanks @zhongwuzw for driving this conversation, it's great to have the migration code in place. |
New Pull Request Checklist
I have read and understood the CONTRIBUTING guide
I have read the Documentation
I have searched for a similar pull request in the project and found none
I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)
I have added the required tests to prove the fix/feature I am adding
I have updated the documentation (if necessary)
I have run the tests and they pass
I have run the lint and it passes (
pod lib lint
)This merge request fixes / reffers to the following issues: ...
Pull Request Description
5.x
? We changed the default disk cache name of directory, we can't just simply do the rename operation, because the older version's directory is still exist (ps. if user upgrade from older to5.x
), and may contains many images, if we do not handle these images, they would always exists, cannot access, delete or anything.options
.