Skip to content
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

[CIS-789,CIS-790] Use custom keys for image caching and Load image thumbnails correctly #1111

Merged
merged 5 commits into from Jun 1, 2021

Conversation

skorepak
Copy link
Contributor

@skorepak skorepak commented May 25, 2021

In this PR

  • I created image CDN protocol to filter out query parameters from image URL and add thumbnail size parameters to the URL
  • used the provider to fix an issue with constantly reloading images

Links

https://stream-io.atlassian.net/browse/CIS-789
https://stream-io.atlassian.net/browse/CIS-790

@codecov-commenter
Copy link

codecov-commenter commented May 25, 2021

Codecov Report

Merging #1111 (1a0fbd5) into main (4c31afb) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1111   +/-   ##
=======================================
  Coverage   91.36%   91.36%           
=======================================
  Files         216      216           
  Lines        9215     9215           
=======================================
  Hits         8419     8419           
  Misses        796      796           
Flag Coverage Δ
llc-tests 91.36% <ø> (ø)
llc-tests-ios12 91.36% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c31afb...1a0fbd5. Read the comment docs.

Copy link
Contributor

@VojtaStavik VojtaStavik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the correct approach 👍

Sources/StreamChatUI/Utils/ImageCDN.swift Outdated Show resolved Hide resolved
Sources/StreamChatUI/Utils/ImageCDN.swift Outdated Show resolved Hide resolved
Sources/StreamChatUI/Utils/ImageCDN.swift Outdated Show resolved Hide resolved
@skorepak skorepak force-pushed the CIS-789-Use-custom-keys-for-image-caching branch 2 times, most recently from 64c9755 to 8fc7eec Compare May 27, 2021 12:09
@skorepak skorepak marked this pull request as ready for review May 27, 2021 12:11
@skorepak skorepak force-pushed the CIS-789-Use-custom-keys-for-image-caching branch 2 times, most recently from 7a6ba0a to cb12be3 Compare May 28, 2021 10:29
@skorepak skorepak changed the title [CIS-789] Use custom keys for image caching [CIS-789,CIS-790] Use custom keys for image caching and Load image thumbnails correctly May 28, 2021
@skorepak
Copy link
Contributor Author

Added function to load thumbnail of preferred size and renamed protocol to ImageCDN.
I'm wondering whether to limit the thumbnail URL just for our Image CDN. Anybody nows?

Sources/StreamChatUI/Utils/ImageCDN.swift Show resolved Hide resolved
Sources/StreamChatUI/Utils/ImageCDN.swift Outdated Show resolved Hide resolved
Sources/StreamChatUI/Utils/ImageCDN.swift Outdated Show resolved Hide resolved
Sources/StreamChatUI/Utils/ImageCDN.swift Outdated Show resolved Hide resolved
Sources/StreamChatUI/Utils/ImageCDN.swift Show resolved Hide resolved
Sources/StreamChatUI/Components.swift Outdated Show resolved Hide resolved
@skorepak skorepak force-pushed the CIS-789-Use-custom-keys-for-image-caching branch from cb12be3 to f6ea2a4 Compare May 31, 2021 10:58
Copy link
Contributor

@VojtaStavik VojtaStavik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few comments to the API design 👍

from url: URL?,
placeholder: UIImage? = nil,
resizeAutomatically: Bool = true,
requestThumbnail: Bool = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH this API now feels a bit complex. In the end, it all comes to the question - do you need the image in a specific size? If yes, you should try to get the correct URL and get it.

Maybe there's a way to simplify this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about some enum with associated value like:

enum Resize {
    .resizeAfterDownload
    .requestThumbnail(size: CGSize?)
    .none
}

But you didn't like adding an extra option for ImageCrop and this would be the same. Adding extra public enum just for this. I would say it's a bit extensive, but not that complex.

I'm open to suggestions on how to simplify this

@skorepak skorepak force-pushed the CIS-789-Use-custom-keys-for-image-caching branch 2 times, most recently from e88d0db to 1a0fbd5 Compare May 31, 2021 20:14
@skorepak skorepak force-pushed the CIS-789-Use-custom-keys-for-image-caching branch from 1a0fbd5 to 5c4f769 Compare June 1, 2021 13:08
@skorepak skorepak closed this Jun 1, 2021
@skorepak skorepak reopened this Jun 1, 2021
@skorepak skorepak force-pushed the CIS-789-Use-custom-keys-for-image-caching branch from 4788ce0 to 0518c54 Compare June 1, 2021 14:30
return size
}

private let sizeProvider: () -> CGSize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should return CGSize? rather than using .zero as the fallback?

}

public var identifier: String {
"com.github.kean/nuke/lateResize"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we make this unique every time we create a processor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to figure out if it matters or not. Nuke docs don't say anything and the original Resize is adding just the parameters of the processor. If you create two Resize processors with the same size parameter, they will have the same identifier. Since we have size closure and getting the size is waiting synchronously for the main queue (may be expensive), I decided to remove it.

@skorepak skorepak force-pushed the CIS-789-Use-custom-keys-for-image-caching branch from 0518c54 to eba4886 Compare June 1, 2021 15:04
@skorepak skorepak merged commit 3eab0cf into main Jun 1, 2021
@skorepak skorepak deleted the CIS-789-Use-custom-keys-for-image-caching branch June 1, 2021 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants