Problem/Motivation

When one image is used in two nodes, the files management page (admin/content/files) shows as expected "Used in 2 places". However the file usage detail view (admin/content/files/usage/[fid]) shows four lines.

Steps to reproduce

Here is some code to reproduce the issue (if you use the same file in 2 nodes, you will have 4 rows on the file usage page; if you use the same file in 3 nodes, you will have 9 rows on the file usage page; if you use the same file in 4 nodes, you will have 16 rows on the file usage page, etc.):

$file = \Drupal\file\Entity\File::create([
  'uri' => 'public://test.png',
]);
$file->save();
$node = \Drupal\node\Entity\Node::create([
  'type' => 'article',
  'title' => 'Test 1',
  'field_image' => ['target_id' => $file->id()],
]);
$node->save();
$node = \Drupal\node\Entity\Node::create([
  'type' => 'article',
  'title' => 'Test 2',
  'field_image' => ['target_id' => $file->id()],
]);
$node->save();
drupal_flush_all_caches();

Proposed resolution

Add a 'distinct' to the file usage view.

Remaining tasks

  • Discuss the solution
  • Make a patch
  • Review the patch

h3 id="summary-ui-changes">User interface changes

None. Using a different default configuration value.

API changes

none

Data model changes

none

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan created an issue. See original summary.

Sutharsan’s picture

Status: Active » Needs review
FileSize
841 bytes

This patch adds the proposed 'distinct' to the view.

dawehner’s picture

Version: 8.1.x-dev » 8.0.x-dev
Issue tags: +Needs tests

A bug should be fixed against 8.0.x, shouldn't it?

Sutharsan’s picture

FileSize
843 bytes

Ignore the #1 patch. This patch has the distinct applied to the right view.

The last submitted patch, 2: core-views-file-usage-2560937-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: core-views-file-usage-2560937-2.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jb044’s picture

We see the same behaviour in Drupal 8 (8.9.13) when files are used in multiple entities, the probleem seems to be the double JOIN in the views query:

SELECT file_usage.id AS file_usage_id, file_usage.type AS file_usage_type, file_usage.module AS file_usage_module, file_usage.count AS file_usage_count, file_managed.fid AS fid
FROM
{file_managed} file_managed
INNER JOIN {file_usage} file_usage_file_managed ON file_managed.fid = file_usage_file_managed.fid
LEFT JOIN {file_usage} file_usage ON file_managed.fid = file_usage.fid
WHERE (file_managed.fid = '6659')
ORDER BY file_usage_id ASC
LIMIT 11 OFFSET 0
jb044’s picture

We see the same behaviour in Drupal 8 (8.9.13) when files are used in multiple entities, the probleem seems to be the double JOIN in the views query:

SELECT file_usage.id AS file_usage_id, file_usage.type AS file_usage_type, file_usage.module AS file_usage_module, file_usage.count AS file_usage_count, file_managed.fid AS fid
FROM
{file_managed} file_managed
INNER JOIN {file_usage} file_usage_file_managed ON file_managed.fid = file_usage_file_managed.fid
LEFT JOIN {file_usage} file_usage ON file_managed.fid = file_usage.fid
WHERE (file_managed.fid = '6659')
ORDER BY file_usage_id ASC
LIMIT 11 OFFSET 0

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
darvanen’s picture

This came up as the Bug Smash Initiative target of the day.

I'm unsure how to replicate this issue on a fresh standard install as the file and image field widgets don't allow for re-use. Are you using media library or similar here? Please provide steps to reproduce.

darvanen’s picture

Status: Needs work » Postponed (maintainer needs more info)

Thank you for reporting and working on this bug. We rely on issue reports like this one to resolve bugs and improve Drupal core.

Since we need more information to move forward with this issue, I am making the status Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

mfb’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work

Added some reproduce code to the issue summary.

mfb’s picture

Issue summary: View changes

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2632372: Repeated file_usages when listing them

I found a duplicate of this problem, #2632372: Repeated file_usages when listing them. It is later but it has more discussion and patches.

I am closing this as a duplicate and moving credit.