Skip to content

[BUG] Remove views table column in Gravity Forms admin view #2786

@curtismchale

Description

@curtismchale

Issue

Pertinent to #2785

When we view all forms there is a view count. This seems to create a bunch of extra queries. The issue above added an index to the table being called so we may never see the issue again.

If we are still seeing the query causing SQL issues a next step is to remove the views column from the all form table view.

If the index doesn't fully resolve the query volume, add the following to wp-proud-core/plugin_override/gravityforms/proud-gravityforms.php inside proud_gravityforms_init(), after the
gform_disable_post_creation line:

  // Remove view count and conversion columns from the form list.
  // Prevents the expensive GROUP BY aggregate query on wp_gf_form_view.
  // The query runs unconditionally in GFFormsModel::get_forms() regardless
  // of what columns are displayed, so we also pre-populate GFCache to
  // short-circuit it before it hits the DB.
  add_filter( 'gform_form_list_columns', __NAMESPACE__ . '\\proud_remove_gf_view_columns' );
  add_action( 'admin_init', __NAMESPACE__ . '\\proud_suppress_gf_view_count_query' );

Then add these two functions anywhere in the same file, inside the if ( class_exists( 'GFCommon' ) ) block:

  /**
   * Removes the Views and Conversion columns from the GF form list.
   * Conversion is derived from view count so is also meaningless without it.
   */
  function proud_remove_gf_view_columns( $columns ) {
      unset( $columns['view_count'] );
      unset( $columns['conversion'] );
      return $columns;
  }

  /**
   * Pre-populates GFCache with an empty view count result so
   * GFFormsModel::get_forms() never executes the aggregate query.
   * GFCache checks its static in-memory array first, so this is a no-op
   * on the DB — it just prevents the query from being attempted at all.
   */
  function proud_suppress_gf_view_count_query() {
      if ( ! is_admin() || ! class_exists( 'GFCache' ) ) {
          return;
      }
      if ( ! \GFCache::get( 'get_view_count_per_form' ) ) {
          \GFCache::set( 'get_view_count_per_form', [], true, 30 );
      }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions