I'd like to have the query count per resource available in responce. It's not specified in JSON API, but perhaps it can be treated as meta data:

Where specified, a meta member can be used to include non-standard meta-information.

.

Some further discussion: http://discuss.jsonapi.org/t/pagination-controls/422/

CommentFileSizeAuthor
#7 2877041--include-count.patch6.51 KBdpolant
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tormi created an issue. See original summary.

tormi’s picture

Title: Provide query count » Provide the query count
Issue summary: View changes
e0ipso’s picture

dawehner’s picture

The query count totally can be helpful, but I suggest to not expose it by default. Counting all elements can be a huge performance loss.

e0ipso’s picture

Like @dawehner suggested, we should make sure this behavior is opt-in.

I see this as a global configuration. You either add counts everywhere or nowhere.

slucero’s picture

It doesn't account for the configuration options being discussed here, but for anyone using already using the work in #2746939: [FEATURE] Add pagination metadata as well, I've shared an updated patch to include the total result count in the meta section as described here.

See #2746939-49: [FEATURE] Add pagination metadata for the patch and interdiff specifically adding this to the meta section.

dpolant’s picture

Status: Active » Needs review
FileSize
6.51 KB

This patch adds an include_count config value to the schema and adds a form element on the settings form for setting it. Configurable resource types then look at this global value when deciding the result of their includeCount method.

For more background, see https://www.drupal.org/node/2746939#comment-12136652

e0ipso’s picture

Status: Needs review » Fixed

I made two minor changes on commit.

  1. +++ b/src/ResourceType/ConfigurableResourceType.php
    @@ -27,6 +28,11 @@ class ConfigurableResourceType extends ResourceType {
    +   * @var ConfigFactoryInterface
    

    We need the FQN.

  2. +++ b/src/ResourceType/ConfigurableResourceType.php
    @@ -40,11 +46,12 @@ class ConfigurableResourceType extends ResourceType {
        * @param \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager $enhancer_manager
        *   Plugin manager for enhancers.
        */
    -  public function __construct($entity_type_id, $bundle, $deserialization_target_class, JsonapiResourceConfig $resource_config, ResourceFieldEnhancerManager $enhancer_manager) {
    +  public function __construct($entity_type_id, $bundle, $deserialization_target_class, JsonapiResourceConfig $resource_config, ResourceFieldEnhancerManager $enhancer_manager, ConfigFactoryInterface $config_factory) {
    

    The docblock for the new parameter is missing.

  • e0ipso committed 1a57e11 on 8.x-1.x authored by dpolant
    feat(Links): Provide the query count (#2877041 by dpolant, e0ipso, tormi...

Status: Fixed » Closed (fixed)

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