It seems that this module have some performance issues.
I had an issue that made the site crawl and then started to investigate what led to the issue. In my New Relic report I get this result that Metatag module is the most time consuming module I have installed and it is the same if I select 30 minutes or 7 days.

It seems that the hook in question is the page_attachments since that have the same pattern when looking at hooks instead of modules.

Any suggestions? Are the metatags getting properly cached?

Comments

jonasdk created an issue. See original summary.

damienmckenna’s picture

Title: Performance issue » Metatag performance poor?
Status: Active » Postponed

Without knowing more, it's hard to know what's going on.

The module itself doesn't do any caching, instead it relies upon Drupal's entity caching.

I'm going to mark this Postponed for now because we'll need to come back to it later.

damienmckenna’s picture

Version: 8.x-1.0-beta5 » 8.x-1.x-dev
socialnicheguru’s picture

It was the combination with schema_metatag module that slowed things down not the metatag module itself.

socialnicheguru’s picture

This issue gives more context and the reason why: https://www.drupal.org/project/schema_metatag/issues/2958733#comment-125...

This is true if you add the field to your content type. You only need the metatag field if you want to override metatag values at the individual node level. If you don't need that, leave the metatag field off.

The problem is that the metatag module creates a gigantic form element with all possible values and displays that on each metatag field. The only way to keep things out of that form is to disable modules you don't want. It would be nice if there was a way to limit the things that show up on that form to only a subset of the form elements, without actually disabling modules, but currently there is not.

socialnicheguru’s picture

Related issues: +#2958733: Performance Impact
muranod’s picture

@SocialNicheGuru I just discovered this, though I had a "keywords" field based on the Metatag module in my content type for 7 or 8 months with no issues. Suddenly, the node edit for started hanging for 30 - 40 seconds each time I opened it, and each time I opened a paragraph within that form.

Keywords was my field name for the Metatag module's Advanced meta tags field in the node edit form. When I disabled display of that field, the node edit form loaded quickly. Strange that it only now started causing issues. I discovered this by creating a new content type and creating each field from the old type, and testing the form each step of the way.

karens’s picture

Status: Postponed » Needs review
StatusFileSize
new11.45 KB

I created a patch that adds a settings form where you can identify the specific groups you want to display on each entity type / bundle combination, then adjusts the default form and the field form if specific groups are identified. With the patch, both the default forms and the node edit forms load much more quickly.

To use:
- Add the patch.
- Clear caches.
- Go to the new settings form /admin/config/search/metatag/settings
- Select the specific groups you want to see on each entity type/bundle
- Save the settings.
- Go to the default form (i.e. admin/config/search/metatag/node__article) and you should only see the groups you requested.
- If you use the metatag field, go to the node edit form and look for Metatags in the right column and you should only see the groups requested.

damienmckenna’s picture

Status: Needs review » Needs work

@karens: That's a good start, thank you.

I think it'd be better if the global settings didn't limit the form, but the field widget could be limiting via the widget settings.

karens’s picture

I have performance problems on the global settings form, too, which is part of the reason for doing this.

damienmckenna’s picture

Ah. Oh. Wouldn't it be easier to just disable the relevant submodule?

karens’s picture

Nope if you have a site that requires a bunch of them but each on different content types, which is a common use-case for schema metatag. You can't disable anything so everything comes along for the ride in every single place. I'd be happy to screenshare and show you what a horrible UX it is. The default form is practically unusable, the node form is even worse of course. Plus you can't tell which ones are filled out and which are empty when all those unneeded sub-forms are in every place. One of the changes in this patch is to open up the forms that have values instead of collapsing everything but the first one so you can at least see what is filled out.

damienmckenna’s picture

Status: Needs work » Needs review

AH! Now I totally understand. Thank you.

karens’s picture

StatusFileSize
new11.45 KB

There was a typo in the previous patch, updating it.

karens’s picture

Also, the idea is to make this seamless to anyone not having problems. If you don't select specific groups to display in specific places nothing changes. Everything works as it now does. If you have performance problems you can use this, if you don't you can ignore it.

michelle’s picture

The patch in #14 worked for me. It applied cleanly, no errors, and worked as expected. Nice addition.

damienmckenna’s picture

Thanks for the review, Michelle!

damienmckenna’s picture

Issue tags: +TCDrupal2018
marysmech’s picture

Patch #14 works. Thank you.

chr.fritsch’s picture

Status: Needs review » Needs work
+++ b/metatag.links.menu.yml
@@ -3,4 +3,9 @@ entity.metatag_defaults.collection:
+  parent: parent: system.admin_config_search

This breaks the menu system

carsteng’s picture

great @chr.fritsch.
I was wondering why I cannot see some menu items, but hadn't time to invest.

carsteng’s picture

StatusFileSize
new473 bytes
new11.38 KB

So here is an updated patch with the issue from #20

carsteng’s picture

Status: Needs work » Needs review
damienmckenna’s picture

Out of interest, would it be simpler to have this managed via the field widget settings?

karens’s picture

That would only help performance on the field, but there are performance problems on the global forms as well. This patch fixes both.

chr.fritsch’s picture

I think it would be good if it would be possible to configure this also on tag level. We often have the use case that editors want to change the robots.txt settings on node level. But it not necessary to show them all the possibilities of the advanced group.

damienmckenna’s picture

@chr.fritsch: That'd be way overboard, for that just build a new set of fields and use tokens to fill in the values into the tags.

  • DamienMcKenna committed 88afa7c on 8.x-1.x authored by KarenS
    Issue #2691313 by KarenS, carstenG, DamienMcKenna, Michelle, marysmech:...
damienmckenna’s picture

Component: Other tags » User interface
Status: Needs review » Fixed
Parent issue: » #2957104: Plan for Metatag 8.x-1.6

Committed. Thanks KarenS and everyone for working on this!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

martijn de wit’s picture

Having 2 issues using latest Dev of metatags.
1. After getting the latest dev. I get an stack-trace error the new router metatags.settings can not be found. This can be resolved after a drush CR, but I think more people will run into this issue.

2. At /admin/config/search/metatag/settings is now showing all sub module off the metatag module even when those are not installed. For the Schema metatag module it only shows the modules installed but for the submodules of metatag module it just shows every module. I think the user should only be able to select from the modules that are enabled/installed.

-- edit ---
3. I also notice, all (sub)groups in the metatags field on the add/edit node page are now open by default. So when I open the metatag tab, the page extends extremely because all groups are now open by default. I don't know if it caused by this issues. As UX-experience this is not the ideal situation. I think it would be great if the groups are closed by default.

I tried to open the issue again but i'm not allowed to do. So maybe I should have created a new issue....

metatags settings page

drupal 8 module page

kasey_mk’s picture

Thank you. This is tremendously helpful - it makes a huge difference in performance.

On top of that, we have some content types where we want to set the metatag values programmatically based on field values but don't need to allow users to make overrides on individual nodes. I can simply disable the field in the form display or uncheck the schema fields on admin/config/search/metatag/settings if I want to leave some of the other overrides available, and use hook_entity_presave to $entity->set('field_meta_tags', serialize([ TAGS => VALUES ]));

tom.moffett’s picture

StatusFileSize
new16.29 KB

Hi, I ran into this issue as well, and glad I found that this was fixed via the config, so thanks for that! However, unless I am missing something, the Views section is still having this issue and there is no place to configure the Metatag for Views that I saw. Is this something that can be added?

metatag views

damienmckenna’s picture

damienmckenna’s picture

@tom.moffett: Please open a new issue so we can discuss what you're looking for. Thanks.

damienmckenna’s picture

Title: Metatag performance poor? » Option to control which groups are available per entity type/bundle