"Is Micro-content" filter has surprising behavior with non-micronode types

Created on 6 September 2024, 4 months ago
Updated 12 September 2024, 3 months ago

Problem/Motivation

I was going to put in a feature request (still to come!) when I stumbled up some unexpected behavior I would say is buggy.

In short the "Is Micro-content" views filter can get a surprising difference in results when the operator is "!= Yes" vs "= No".

I would expect a content type that does not yet have micronode third_party_settings configured to act like a content type with micronode_is_microcontent set to false.

Update: I noticed this is reported on the project page:

Views will only recognize nodes whose types have this flag at either TRUE or FALSE, but on existing types this will be NULL unless they are re-saved.

I still think we can consider a bug and come up with a fix.

Steps to reproduce

  1. Enable umami.
  2. Enable micronode
  3. Add the "Is Microcontent" views filter to the content admin with the operator of "= No".
  4. View the content admin page and see no results.
  5. Change the operator to "!= Yes"
  6. View the content admin page and see all the things. [edit: we actual see all the micronodes! related but distinct bug]

Proposed resolution

I see that micronode_get_node_types() behaves the way I expect, where FALSE is a presumed default value.

The views filter is written rather differently, though. It adds a where clause that searchs for this string in the node types data table:

$needle = '%{s:25:"micronode\_is\_microcontent";_:' . (int) $this->value . ';}%';
$this->query->addWhere($this->options['group'], 'config.data', $needle, 'LIKE');

This is not my most comfortable area, but I wonder if there's an easy way to OR a condition where micronode\_is\_microcontent does not appear at all in the table. And that would be understood to be identical to the micronode status being false.

Alternatively, it's pretty easy to image an install hook that sets the micronode_is_microcontent to FALSE on all existing node types.

Remaining tasks

User interface changes

Maybe update the filter so that the "is not equal to" option is not available

[edit: this would prevent us from having to fix the bug where the "is not equal to" option doesn't actually do anything]

API changes

"!= YES" and "= NO" would give the same results.

Data model changes

no

πŸ› Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @danflanagan8
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    Whoa, there's actually more bugginess here. It looks like picking "Is not equal to" doesn't actually change the results.

    When I set it to "!= Yes" it shows all my micronodes. When I did that and say "all the things" I had assumed I was seeing all the non-micronodes.

    So there are at least two things that need fixing here.

    First, we should treat the absence of micronode_is_microcontent the same way we treat FALSE.
    Second, we need to either fix or remove the "Is not equal to" setting.

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    I just noticed this on the project page:

    Views will only recognize nodes whose types have this flag at either TRUE or FALSE, but on existing types this will be NULL unless they are re-saved.

  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    I got a bee in my bonnet and pushed something up for this one.

    An install and update hook would probably be sufficient, but I also wanted to address the bug related to "Is not equal to" and generally try to improve the filter's UX.

    The MR addresses the problem without an update hook. And here's what the form looks like afterwards.

    Definitely clearer than it is now (and more functional) though I wouldn't claim to have picked the best wording possible.

    Here's what it looks like now, for reference.

    A little confusing. And the "Is not equal to" isn't functional.

  • First commit to issue fork.
  • Pipeline finished with Skipped
    3 months ago
    #277311
  • Status changed to Fixed 3 months ago
  • πŸ‡ͺπŸ‡ΈSpain marcoscano Barcelona, Spain

    Looks good to me, thank you for contributing!

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    This change seems to have significantly degraded view performance on our site with 14K+ content items.

    After this update, the render time for our content admin view (100 items/page) went from a little over a second to over two minutes. Removing the "Is Micro-content" filter immediately restored previous performance.

    I'm no expert in SQL queries, but maybe the updated where clause leads to issues at scale? I'll try to investigate more as time allows.

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    I'm no expert in SQL queries, but maybe the updated where clause leads to issues at scale?

    Neither am I, though as I was making this change I did worry that "NOT LIKE" was going to be slower than "LIKE". I was hoping that worry was unfounded but perhaps I was right to be concerned.

    Since I'm kind of nuts I had been thinking about how to rework this filter even before the comment from @justcaldwell. It occurred to me that it might make sense to copy off of whatever the normal node type filter does in the query. We'd do a call to micronode_get_micronode_types or whatever to get the content types we need to include. I'm not sure if xtending that filter makes sense, given all the extra configuration options and stuff that filter has. Maybe though.

  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    I updated the query method locally to query more like the bundle filter and I got the tests to pass:

      /**
       * {@inheritdoc}
       */
      public function query() {
        $this->ensureMyTable();
        $micronode_bundles = array_keys(micronode_get_node_types(TRUE));
        if ($this->value) {
          // Restrict to micronodes.
          if ($micronode_bundles) {
            $this->query->addWhere($this->options['group'], "$this->tableAlias.type", $micronode_bundles, 'IN');
          }
          else {
            // If there are no micronode bundles views should return nothing.
            // Modeled after Drupal\Core\Database\Query::alwaysFalse().
            $this->query->addWhereExpression($this->options['group'], '1 = 0');
          }
        }
        else {
          // Exclude micronodes.
          if ($micronode_bundles) {
            $this->query->addWhere($this->options['group'], "$this->tableAlias.type", $micronode_bundles, 'NOT IN');
          }
        }
      }
    

    I'm trying to figure out the best way to push this up for a new MR.

  • Pipeline finished with Canceled
    3 months ago
    Total: 179s
    #281275
  • Pipeline finished with Success
    3 months ago
    Total: 149s
    #281282
  • Status changed to Fixed 3 months ago
  • πŸ‡ͺπŸ‡ΈSpain marcoscano Barcelona, Spain

    Can we please open a new ticket for this and create the MR there?
    @justcaldwell it would be great if you could compare the current fix with this new proposal and see if it solves the performance impact you are experiencing? Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    That did the trick. I applied the patch and re-enabled the filter β€” performance is back on par with the previous release. Thanks for the quick response @danflanagan8! πŸ™

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    I just created πŸ› Degraded query performance after "Is Micro-content" filter change Active . I'll create an MR using Dan's code in a bit.

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

Production build 0.71.5 2024