-
Notifications
You must be signed in to change notification settings - Fork 64
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
RUM-6195: Allow ResourcesLruCache to work with any key #2418
Conversation
d4f5994
to
256a4aa
Compare
256a4aa
to
8743eb1
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2418 +/- ##
===========================================
+ Coverage 70.12% 70.22% +0.10%
===========================================
Files 767 767
Lines 28490 28513 +23
Branches 4778 4782 +4
===========================================
+ Hits 19977 20021 +44
+ Misses 7170 7156 -14
+ Partials 1343 1336 -7
|
d26f4d8
to
56c49e9
Compare
56c49e9
to
ebafe41
Compare
...eplay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/resources/Cache.kt
Outdated
Show resolved
Hide resolved
wireframeIndex++ | ||
val resourceCacheKey = if (resourceIdCacheKey != null) { | ||
"$resourceIdCacheKey" + "_$wireframeIndex" | ||
} else { | ||
null | ||
} |
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.
does it have any impact on the cache hit metric?
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've done some measurements and the hit metric isn't impacted
@@ -82,18 +84,25 @@ interface ImageWireframeHelper { | |||
clipping: MobileSegment.WireframeClip? = null, | |||
shapeStyle: MobileSegment.ShapeStyle? = null, | |||
border: MobileSegment.ShapeBorder? = null, | |||
prefix: String? = DRAWABLE_CHILD_NAME | |||
prefix: String? = DRAWABLE_CHILD_NAME, | |||
resourceIdCacheKey: String? |
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.
are we not assigning here the default null
value on purpose? other nullable args in this function have it.
@@ -115,7 +115,8 @@ internal class DefaultImageWireframeHelper( | |||
clipping: MobileSegment.WireframeClip?, | |||
shapeStyle: MobileSegment.ShapeStyle?, | |||
border: MobileSegment.ShapeBorder?, | |||
prefix: String? | |||
prefix: String?, | |||
resourceIdCacheKey: String? |
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.
why not give a null value as default since in a lot of case it's not used?
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 wanted to avoid as much as possible default values so that it's more explicit what is being passed
"$resourceIdCacheKey" + "_$wireframeIndex" | ||
} else { | ||
null | ||
} |
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.
what's the reason this modification is only applied for CompoundDrawable?
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.
CompoundDrawables can have multiple drawables associated, so in the case that an override key is provided the drawables need to be differentiated in the cache but if no key is provided then it will default to the original behavior
@@ -65,6 +65,8 @@ interface ImageWireframeHelper { | |||
* @param shapeStyle provides a custom shape (e.g. rounded corners) to the image wireframe | |||
* @param border provides a custom border to the image wireframe | |||
* @param prefix a prefix identifying the drawable in the parent view's context | |||
* @param customResourceIdCacheKey an optional key with which to cache or retrieve from the resource cache. | |||
* If this key is not provided then one will be generated from the drawable. | |||
*/ | |||
// TODO RUM-3666 limit the number of params to this function | |||
fun createImageWireframeByDrawable( |
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.
side note: it is a bit strange that detekt
doesn't flag this method as a method with long list of arguments. Do we have this rule enabled?
...otlin/com/datadog/android/sessionreplay/internal/recorder/resources/ResourcesLRUCacheTest.kt
Outdated
Show resolved
Hide resolved
...otlin/com/datadog/android/sessionreplay/internal/recorder/resources/ResourcesLRUCacheTest.kt
Outdated
Show resolved
Hide resolved
...otlin/com/datadog/android/sessionreplay/internal/recorder/resources/ResourcesLRUCacheTest.kt
Outdated
Show resolved
Hide resolved
Closed as the contents was squashed into this pr: #2448 |
What does this PR do?
Modifies
ResourcesLruCache
to accept a caller-provided key as input rather than always generating the key from the resource. Add thecustomResourceIdCacheKey
parameter to ImageWireframeHelper so that the key can be passed from the outside.Motivation
This is necessary to support resources passed from Jetpack Compose and React Native.
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)