Problem/Motivation
When you have more than one usage for a file, in the list of usages of this file (the page_2 of views.view.files.yml), each usage is listed the same amount of times as results are. As the view is doing a join between file_managed and file_usage and then again another join with file_managed with the result.
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
This is due to a double join between file_managed and file_usage, remove the duplicated join.
We should remove the following duplicate join of file_managed
from the FileViewsData.php
$data['file_usage']['table']['join'] = [
'file_managed' => [
'field' => 'fid',
'left_field' => 'fid',
],
Remaining tasks
- Needs review
User interface changes
N/A
API changes
TBD
Data model changes
N/A
Release notes snippet
N/A