Problem/Motivation

Why does views_field_config_create() invalidate the views data cache? Why doesn't that only happen when a field is saved? The field isn't even persisted yet, so if another hook will then fetch views data, it will not be visible yet?

This is especially bad because field purging apparently invokes the create hook, during cron runs:

#0 core/modules/views/src/ViewsData.php (325, invalidateTags)
#1 core/modules/views/views.module (465, clear)
#2 (0, views_field_config_create)
#3 core/lib/Drupal/Core/Extension/ModuleHandler.php (395, call_user_func_array)
#4 core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php (336, invokeAll)
#5 core/lib/Drupal/Core/Entity/EntityStorageBase.php (197, invokeHook)
#6 core/modules/field/src/FieldConfigStorage.php (134, create)
#7 core/includes/entity.inc (166, loadByProperties)
#8 core/modules/field/field.purge.inc (83, entity_load_multiple_by_properties)
#9 core/modules/field/field.module (145, field_purge_batch)

Pretty sure this is the wrong hook and is supposed to be insert?

It's also likely that this shouldn't even invoke that hook but it still makes no sense.

Proposed resolution

Switch to the insert() hook.

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#1 field-create-views-2496261-1.patch593 bytesberdir

Comments

berdir’s picture

Status: Active » Needs review
StatusFileSize
new593 bytes

And here's a patch for that.

berdir’s picture

Title: Field Purging invalidates views_data caches repeatedly » Field Purging invalidates views_data caches as it uses the wrong hook

I guess repeatedly only happens when you have multiple fields, improving title

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quickfix

OH yeah, that seems to make sense.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 6ebade7 and pushed to 8.0.x. Thanks!

  • alexpott committed 6ebade7 on 8.0.x
    Issue #2496261 by Berdir: Field Purging invalidates views_data caches as...

Status: Fixed » Closed (fixed)

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