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

remove cached owner info #6028

Merged
merged 2 commits into from Nov 22, 2016
Merged

remove cached owner info #6028

merged 2 commits into from Nov 22, 2016

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Nov 4, 2016

fix #5917

@@ -103,6 +104,15 @@ export class Resource {
Resource.forElementOptional(element).updateOwner(owner);
}
element[OWNER_PROP_] = owner;
// Need to clear owner cache for all child elements
Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely want this to be recursive, as it could be <owner> <child> <div> <grandchild>. Using Resources#discoverResourcesForElement_ or #discoverResourcesForArray_ would do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, it needs to be recursive. However I don't think Resources#discoverResourcesForElement_ or #discoverResourcesForArray_ will do the work here. In the case of <owner> <child> <div> <grandchild> #discoverResourcesForElement_ will stop searching when it reaches <child>. Thus will never clear the cached value for <grandchild>. Also what if <owner><child><div><grandchild><grandgrandchild>?
A correct approach I can think of would be finding all the children, grandchildren .... (sorry I'm too lazy find the opposite word for ancestor 😄), but I assume it would be time consuming.

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 switched to getElementByClassName('-amp-element') which finds me all the amp children.
It's same concept as discoverResourcesForElement_ except discoverResourcesForElement doesn't work in case <owner><child><grandchild><greatgrandchild> because it will not clear cache for greatgrandchild.
PTAL

@@ -190,7 +200,7 @@ export class Resource {

/**
* Update owner element
* @param {!AmpElement} owner
* @param {AmpElement|undefined} owner
Copy link
Contributor

Choose a reason for hiding this comment

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

How would this be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when I want to clear the cached value and reset it to undefine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I didn't see that.

@zhouyx zhouyx merged commit be23f10 into ampproject:master Nov 22, 2016
@zhouyx zhouyx deleted the fix-setowner branch November 22, 2016 21:30
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* owner

* use getElementsByClassName
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* owner

* use getElementsByClassName
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.

Recursively un-cache Resource Owner
2 participants