Right now using the following module makes it easy to query but becomes super difficult when trying to query the database table that has several thousand records including an additional 800k+ records in the data table.

I have a suggestion to query the webform_submission table first and then only grab ids that have values provided in the conditions.

Additionally this will allow for fields on the webform_submission table to also be queried, example use cases are if you'd like to get items within a specific timeframe. Additionally this rewrites the query to use the Sql Select command for non SQL based systems.

I had previously added this https://www.drupal.org/project/webform_query/issues/3064363 but then decided that if a rewrite happens it won't necessarily matter.

Comments

sean_e_dietrich created an issue. See original summary.

sean_e_dietrich’s picture

Issue summary: View changes
Related issues: +#3064363: Coding Standard Violations
imclean’s picture

Thanks for the suggestions, the query could certain do with some optimisations. Can you provide any benchmarks?

Additionally this will allow for fields on the webform_submission table to also be queried

This is something I had hoped to support at some point. I'll need to review the patch in more detail.

imclean’s picture

I'm looking into this now, specifically querying the webform_submission table.

I chose to use query() over select() for performance reasons. See Introduction to Dynamic Queries:

Note: in 90% of select query use cases you will have a static query. If in a critical performance path, you should use query() instead of select() for performance reasons.

imclean’s picture

Status: Needs review » Needs work

There are a few unrelated changes which make this patch harder to review. Doc block additions and changes to naming conventions mean we're not comparing like for like. I'll need to see if I can extract the bare minimum to including querying the webform_submission table.

imclean’s picture

Category: Bug report » Feature request
Status: Needs work » Needs review
StatusFileSize
new4.88 KB
  1. Retained current execute() method returning the same result type for compatibility
  2. Added method processQuery() to return a database statement. This can be used to change the result type. E.g. $query->processQuery()->fetchCol();
  3. Added "table" parameter to addCondition() to allow arbitrary tables which have a "sid" column to be queried
  4. Stuck with pure SQL for performance
  5. Now queries webform_submission and other arbitrary non-EAV tables first for performance
  6. All methods are still public at the moment, this could potentially be changed in a separate issue
  7. Camel case isn't used internally, this could be changed in a separate issue.
  8. Typos not fixed.

The last 3 changes could potentially be handled within the same general tidying up issue.

Example:

$query = \Drupal::service('webform_query');

$query->addCondition('field_name', 'value')    
  ->setWebform('my_webform')
  ->addCondition('uid', 1, '=', 'webform_submission');

$results = $query->processQuery()->fetchCol();

  • imclean committed 1a7e27c on 8.x-1.x
    Issue #3064366 by imclean, sean_e_dietrich: Slow Performance
    
imclean’s picture

Committed anyway. Try the latest dev.

imclean’s picture

Status: Needs review » Fixed

Let me know if there are any issues.

Status: Fixed » Closed (fixed)

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