Problem/Motivation

In some cases, due to data corruption or incorrect file configuration, there may be multiple file entries in file_managed that point to the same file URI.

Usually only one of them has usage but cannot be deleted, the unused due will delete the file used by the one with usage.

Dulicated file entries

Issue fork xray_audit-3508125

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

frouco created an issue. See original summary.

antonio nunez’s picture

Assigned: Unassigned » antonio nunez

antonio nunez’s picture

StatusFileSize
new54.87 KB

A new report has been created that detects duplicate files in the file_managed table and suggests actions to take. Now, the report lists the following information for each set of duplicate files:

  • File URI: The location of the file on the Drupal system.
  • File name: Extracted from the URI.
  • Main FID: The file identifier that is in active use.
  • Unused FIDs: Identifiers of duplicate files without reference in file_usage.
  • Recommendation: A suggestion based on the status of the duplicate files.

Scenarios:

  1. If there is a main file in use and unused duplicates: It is recommended to keep the main file and delete the unused duplicates.
  2. If all duplicate files are unused: It is recommended to remove all duplicates as none are being used.
  3. If all duplicate files have active usage: A manual review is required.
tunic’s picture

Also, I guess that process can be done directly using SQL. I mean writing a SQL query that returns what the values calculated in $main_fid and $unused_fids. Probably, this is not trivial, but if done will solve many performance problemas with sites that have huge number of files.

antonio nunez’s picture

Optimized data handling and split the logic for displaying recommendation messages.

antonio nunez’s picture

StatusFileSize
new55.76 KB
antonio nunez’s picture

Assigned: antonio nunez » Unassigned
Status: Active » Needs review
tunic’s picture

It looks good to me, but I'll wait for @lpeidro review.

Thanks!

tunic’s picture

lpeidro’s picture

Version: 1.5.12 » 2.x-dev

I change dev branch (2.x-dev)

lpeidro’s picture

We improved the login process to enhance performance. Before this modification, a request was executed with a WHERE clause, which could cause performance issues on large sites. We moved some of the logic from PHP to SQL, using strategies such as GROUP BY and HAVING.

lpeidro’s picture

Status: Needs review » Reviewed & tested by the community

It works as expected. I merge the branch.
Thank you Antonio.

eduardo morales alberti’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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