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

Implemented tagging responses with comment cache tags #137

Merged
merged 6 commits into from Dec 21, 2018

Conversation

Toflar
Copy link
Member

@Toflar Toflar commented Oct 18, 2018

Implementation for #135

@Toflar Toflar force-pushed the comments-cache-invalidation branch from 02e4f2c to 5bbc6bc Compare October 18, 2018 15:17
@@ -1229,6 +1229,23 @@ protected function getCacheTags($table, array $ids = array(), $parentTable = '',
$tags[] = $ns . $parentTable . '.' . $parentId;
}

// Trigger the oncachetags_callback
if (\is_array($GLOBALS['TL_DCA'][$table]['config']['oncachetags_callback']))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if I like adding a new callback. @contao/developers Is this still how we do it nowadays?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like adding an event here. It's still old fashioned DCA stuff. If we have a new driver, then we might go a different direction.

Copy link
Member

Choose a reason for hiding this comment

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

I'm generally fine with the callback principle. The markup also works with our new callback service tags.
However, the callback is strange, because it does not pass the datacontainer object, and (almost?) all other callbacks do that. The callback is also missing some arguments (ptable stuff?) and I would expect to return the tags array (or actually return the tags I want to have merged into the array).

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no DC, you don't need one. You also don't need anything else (ptable). I could adjust the return value but it makes no sense to me.

Copy link
Member

Choose a reason for hiding this comment

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

I assume you're right, but it's just kinda inconsistent with most other callbacks. I only question if this is clearly backend related? So is it only supposed to set/clear tags on backend operations? Then it totally makes sense in the DCA. But what if we need to clear tags if the member data is edited in the front end?

@leofeyer leofeyer added this to the 4.7.0 milestone Oct 19, 2018
@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Oct 22, 2018
@leofeyer leofeyer force-pushed the master branch 2 times, most recently from c75098f to 420f146 Compare November 3, 2018 14:58
@leofeyer leofeyer removed the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Nov 22, 2018
@Toflar
Copy link
Member Author

Toflar commented Nov 22, 2018

Modify the methods so they actually do get a DataContainer instance and see if I can keep it BC.

@leofeyer
Copy link
Member

As discussed in Mumble on November 22nd:

Modify the methods so they actually do get a DataContainer instance and see if I can keep it BC.

@Toflar
Copy link
Member Author

Toflar commented Nov 27, 2018

Okay, so BC is impossible but tbh I don't think anyone has already overridden one of the methods in their drivers. Maybe I should make them private anyway, now that we have a callback?
The callback now feels a lot more natural because it gets a dc and the existing tags and expects the modified tags in return. It shows that it really is a callback :)
However, I don't know how to implement it in the reviseTable method. I noticed that there's also no ondelete_callback triggered there. Shouldn't we generate a $dc with all the basic values (id, table, ptable, and activeRecord) and also trigger the ondelete_callback there? If so, I could also call invalidateTags($dc) just the same way then. @contao/developers

@leofeyer
Copy link
Member

leofeyer commented Nov 29, 2018

The easiest solution would probably be to execute

if (System::getContainer()->has('fos_http_cache.cache_manager'))
{
	$cacheManager = System::getContainer()->get('fos_http_cache.cache_manager');
	$cacheManager->invalidateTags($this->getCacheTags($this->strTable, $ids));
}

in the reviseTable() method.

@Toflar
Copy link
Member Author

Toflar commented Nov 29, 2018

getCacheTags() now wants a DataContainer.

@leofeyer
Copy link
Member

leofeyer commented Nov 29, 2018

Bummer. Then I guess we have to create a data container object. Or maybe we were wrong about the changes in the first place?

@leofeyer leofeyer force-pushed the master branch 2 times, most recently from cb069f4 to 10ba742 Compare December 4, 2018 15:26
@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Dec 6, 2018
@leofeyer leofeyer removed the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Dec 20, 2018
@Toflar
Copy link
Member Author

Toflar commented Dec 20, 2018

As discussed in Mumble: Generate a DC for every ID that's going to be deleted and pass this to the invalidation method before the record is actually deleted.

@Toflar
Copy link
Member Author

Toflar commented Dec 20, 2018

Done, ready to review 😄

@leofeyer
Copy link
Member

After this PR has been merged, we should also fix existing $dc->id calls (e.g. here).

{
if (!System::getContainer()->has('fos_http_cache.cache_manager'))
{
return;
}

// Filter empty tags
$tags = array_filter(array_unique($tags));
$tags = $this->getCacheTags($dc);
Copy link
Member

Choose a reason for hiding this comment

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

Now that this method is no longer used anywhere else, we might as well remove it and execute the logic here. Then it would also become more obvious how the callback should be named: oninvalidate_cache_tags_callback (similar to onrestore_version_callback)

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice input! You're right, changed right away: f183f3a

@leofeyer
Copy link
Member

One last thing regarding this change:

			case 'id':
				$this->intId = $varValue;
				break;

Could there be someone out there who relied on $dc->id not changing $dc->intId? Then it would be a BC break for them. On the other hand I don't think this use-case has ever been intended.

@Toflar
Copy link
Member Author

Toflar commented Dec 21, 2018

I think it was not. Would be very strange to have different id's there.

@leofeyer leofeyer merged commit dbc3a97 into contao:master Dec 21, 2018
@leofeyer
Copy link
Member

Thank you @Toflar.

@Toflar Toflar deleted the comments-cache-invalidation branch December 21, 2018 14:22
@leofeyer leofeyer modified the milestones: 4.7.0, 4.7 May 14, 2019
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

3 participants