Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

HARP-12687: User Images are removed from cache when theme is changed #1931

Merged
merged 3 commits into from
Nov 5, 2020

Conversation

StefanDachwitz
Copy link
Contributor

  • remove images from cache only if not used in any other MapView

Signed-off-by: stefan.dachwitz stefan.dachwitz@here.com

Thank you for contributing to harp.gl!

Before requesting a pull request, please remember to check the following documents:

If you are adding new functionality we would highly appreciate if you can describe what is the capability you are adding and even better if you can add some examples. Please also remember to add tests for it.

CI Check

Our bots will check whether your PR can be directly integrated into the mainline. We have some internal integration tests running on the background, our bots will inform you of the next steps and someone from our team will take a look and help if needed!

And please do not forget to sign-off your commit! You can read more about DCO here. But, in short, you just need to use git commit -s or append --signoff when you are committing to the repo.

Happy contributing!

@codecov
Copy link

codecov bot commented Oct 29, 2020

Codecov Report

Merging #1931 into master will increase coverage by 0.01%.
The diff coverage is 88.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1931      +/-   ##
==========================================
+ Coverage   65.25%   65.26%   +0.01%     
==========================================
  Files         293      293              
  Lines       26329    26331       +2     
  Branches     5951     5951              
==========================================
+ Hits        17181    17185       +4     
+ Misses       9148     9146       -2     
Impacted Files Coverage Δ
@here/harp-mapview/lib/image/ImageCache.ts 45.08% <85.29%> (+1.55%) ⬆️
@here/harp-mapview/lib/MapView.ts 73.48% <100.00%> (ø)
@here/harp-mapview/lib/MapViewThemeManager.ts 80.00% <100.00%> (ø)
@here/harp-mapview/lib/image/MapViewImageCache.ts 93.42% <100.00%> (+1.21%) ⬆️

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 d230e1e...abaa399. Read the comment docs.

FraukeF
FraukeF previously approved these changes Oct 30, 2020
Copy link
Contributor

@FraukeF FraukeF left a 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, but as I understand the ticket, but does it solve the issue? Or maybe there is a follow up planned?
Wouldn´t the MapView.userImageCache and the MapView.imageCache register Images referencing the same MapView, and therefore if MapView.imageCache is cleared it would still clear the userImageCache, as described in the ticket?

@atomicsulfate
Copy link
Collaborator

Looks good to me, but as I understand the ticket, but does it solve the issue? Or maybe there is a follow up planned?
Wouldn´t the MapView.userImageCache and the MapView.imageCache register Images referencing the same MapView, and therefore if MapView.imageCache is cleared it would still clear the userImageCache, as described in the ticket?

That's right. This change does not solve the issue.

@StefanDachwitz
Copy link
Contributor Author

That is right, my bad. I caught hung up in fixing the issue when removing shared images (which still happens when the theme is changed).

Copy link
Member

@nzjony nzjony 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 some minor comments.

@@ -25,30 +24,31 @@ declare function createImageBitmap(
): Promise<ImageBitmap>;

/**
* Combines an {@link ImageItem} with a list of {@link MapView}s that reference it.
* Combines an {@link ImageItem} with a list of owners that reference it. Although an owner can be
* any type of object, it should be of type {@link MapViewImageCache}.
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason to mention "it should be of type MapViewImageCache", it doesn't really matter?

Also, please mention that the type is irrelevant, because we are just refcounting, hence any is a valid type.

url: string,
imageData?: ImageData | ImageBitmap,
htmlElement?: HTMLImageElement | HTMLCanvasElement
): ImageItem {
let imageCacheItem = this.findImageCacheItem(url);
if (imageCacheItem !== undefined) {
if (mapView !== undefined && !imageCacheItem.mapViews.includes(mapView)) {
imageCacheItem.mapViews.push(mapView);
if (owner !== undefined && !imageCacheItem.owners.includes(owner)) {
Copy link
Member

Choose a reason for hiding this comment

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

do you need the undefined check? The owner is not optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed it

@@ -120,7 +121,7 @@ export class ImageCache {
htmlElement: htmlElement,
loaded: false
},
mapViews
owners: owners
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
owners: owners
owners: [owner]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

applied your suggestion

@StefanDachwitz
Copy link
Contributor Author

Reworked the PR to use a proper interface for owners.

* remove images from cache only if not used in any other MapView

Signed-off-by: stefan.dachwitz <stefan.dachwitz@here.com>
* made MapViewImageCache (instead of MapView) the owner of an
ImageCacheItem

Signed-off-by: stefan.dachwitz <stefan.dachwitz@here.com>
Signed-off-by: stefan.dachwitz <stefan.dachwitz@here.com>
@StefanDachwitz
Copy link
Contributor Author

retest this please

@nzjony nzjony merged commit ceff1c1 into master Nov 5, 2020
@nzjony nzjony deleted the HARP-12687 branch November 5, 2020 20:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants