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

$this->ptable not available in the DataContainer class #2103

Merged
merged 4 commits into from
Aug 10, 2020

Conversation

leofeyer
Copy link
Member

@leofeyer leofeyer commented Aug 6, 2020

In #2039, we have changed the invalidateCacheTags() method, which now accesses $this->ptable. However, protected $ptable is only declared in the DC_Table class and not in the DataContainer class.

@leofeyer leofeyer added the bug label Aug 6, 2020
@leofeyer leofeyer added this to the 4.9 milestone Aug 6, 2020
@leofeyer leofeyer requested a review from a team August 6, 2020 09:21
@leofeyer leofeyer self-assigned this Aug 6, 2020
@leofeyer leofeyer changed the title Move the $ptable class property to the DataContainer class Move the $ptable property to the DataContainer class Aug 6, 2020
@Toflar
Copy link
Member

Toflar commented Aug 6, 2020

Ah, there are data containers without a ptable. Maybe we should rather check for that in the invalidateCacheTags()? If there's no ptable available, there are also no such tags to invalidate :)

@m-vo
Copy link
Member

m-vo commented Aug 6, 2020

Shouldn't the invalidateCacheTags method rather live in DC_Table?

@leofeyer
Copy link
Member Author

leofeyer commented Aug 6, 2020

Shouldn't the invalidateCacheTags method rather live in DC_Table?

That is what I thought as well, however, there might be custom data containers that need the method. On the other hand, these custom data containers will probably extend from DC_Table. 🤷🏻‍♂️

@Toflar So I move the invalidateCacheTags() to the DC_Table class?

@leofeyer leofeyer changed the title Move the $ptable property to the DataContainer class Do not use $this->ptable in the DataContainer class Aug 10, 2020
@leofeyer
Copy link
Member Author

I have implemented another fix in 76a01b1.

aschempp
aschempp previously approved these changes Aug 10, 2020
Copy link
Member

@aschempp aschempp left a comment

Choose a reason for hiding this comment

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

This will only purge one level up, right? It won't purge tl_page for content elements?

@leofeyer
Copy link
Member Author

Good point! That is another issue indeed (not related to this change though).

@leofeyer
Copy link
Member Author

I guess we have not been traversing through all parent records, because $this->activeRecord only has the current record and the ID of the parent record. And since the method is in the DataContainer class, we would have to overwrite it in each child class, because only the child classes "know" how to retrieve the parent records.

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

No, the parent of the parent is not required to be loaded. This has been discussed before and it's all good the way it is, you just need to pass on the correct tags when tagging.
I don't like this implementation here though. Imho we should check for $dc->table and $dc->activeRecord->pid not the globals.

@leofeyer
Copy link
Member Author

Imho we should check for $dc->table and $dc->activeRecord->pid not the globals.

That is not really possible (see the initial issue description). Unless you want to use property_exists($this, 'ptable')?

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

I think overriding makes sense but imho the callback should be in the DataContainer and in DC_Table we should only add the ptable-pid thing, the rest should be in parent.

@leofeyer
Copy link
Member Author

I still think it is wrong to have this method in the DataContainer class, because the functionality works with DC_Table only. It would even generate wrong tags if called on a DC_Folder object.

Can we not move the method to the DC_Table class and deprecate the original method in the DataContainer class?

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

Can we not move the method to the DC_Table class and deprecate the original method in the DataContainer class?

If it doesn't work we can move it alltogether without a deprecation message.

@leofeyer
Copy link
Member Author

Moved in 115ecca.

@leofeyer leofeyer changed the title Do not use $this->ptable in the DataContainer class $this->ptable not available in the DataContainer class Aug 10, 2020
@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

Removing the pid handling is correct because it's not necessary anyway. You should make sure as a developer to tag your response with all the used resources.

@leofeyer leofeyer merged commit 77832fa into contao:4.9 Aug 10, 2020
@leofeyer leofeyer deleted the fix/ptable branch August 10, 2020 10:26
@ausi
Copy link
Member

ausi commented Aug 10, 2020

Removing the pid handling is correct because it's not necessary anyway. You should make sure as a developer to tag your response with all the used resources.

But for new resources this is not possible as you cannot tag the news archive module with a cache-tag of a not-yet-existing news article. So IMO we have to make sure that creating new elements in a child table actually clears the cache for the parent table (one level up is enought here IMO). For modifications and deletions this should not be necessary I think.

@leofeyer
Copy link
Member Author

leofeyer commented Aug 10, 2020

But as long as there is no news article, there will be no cached news reader page, either, will there?

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

But for new resources this is not possible as you cannot tag the news archive module with a cache-tag of a not-yet-existing news article.

The idea would be to tag all elements working with news with the general contao.db.tl_news and invalidate that when creating a new news entry. Not sure that's the case now but that's the idea.

@leofeyer
Copy link
Member Author

I think this is the case:

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

Yeah we're invalidating the specific tag and the general one on every edit which kinda renders the specific one useless...

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

I mean, it's okay imho if you don't tag the front end list element for example with contao.db.tl_news which you need if you want to invalidate yourself when there's a new news being saved...

@leofeyer
Copy link
Member Author

Can we improve this somehow? E.g. by not invalidating the general tag?

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

Not sure. Invalidating the general tag is kind of like "hey, something regarding the news changed" and maybe you want your response to be invalidated in that case because you don't know. Then we'd need a specific create tag though. But there might be many more. I think this definitely needs an up for discussion label.

@ausi
Copy link
Member

ausi commented Aug 10, 2020

The news list module currently gets tagged with contao.db.tl_news.ID for all shown news articles and contao.db.tl_news_archive.ID for the news archives. So we need to invalidate the parent table IMO to make this work.

@leofeyer leofeyer mentioned this pull request Aug 10, 2020
@leofeyer
Copy link
Member Author

Why? The cache entry for the news list module will be purged if the contao.db.tl_news.ID tag is invalidated.

@ausi
Copy link
Member

ausi commented Aug 10, 2020

If you add a new news article the list module on the website will not be tagged with this new contao.db.tl_news.ID and therefore the new article would not show up. If we invalidate the parent contao.db.tl_news_archive.ID (as we did before this PR) the news list module would show the new article as soon as it was published.

@Toflar
Copy link
Member

Toflar commented Aug 10, 2020

But that's only "by chance". It only works if there is a parent table. If there's not, it wouldn't work. We need special handling for "create".

leofeyer added a commit that referenced this pull request Aug 10, 2020
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2103
| Docs PR or issue | -

Commits
-------

d43984a Also invalidate the ptable cache tags in the DC_Table class
2bb2483 Fix the 'Declaration should be compatible' error
ffa7d96 Revert the changes and only check isset($this->ptable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants