https://bugs.kde.org/show_bug.cgi?id=528354

            Bug ID: 528354
           Summary: Rebuild Thumbnails "scan for changed or non-cataloged
                    items" never converges with duplicate files: each run
                    regenerates the other copy of every duplicate
    Classification: Applications
           Product: digikam
      Version First 9.1.0
       Reported In:
          Platform: Microsoft Windows
                OS: Microsoft Windows
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: Maintenance-Thumbs
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

digiKam 9.1.0, Windows 11, SQLite. Collection: ~218,000 items, of which ~6,000
pairs of byte-identical files (same uniqueHash + fileSize) in different albums
(phone sync folder + themed folders). Identical files are expected to share a
uniqueHash (see bug 523760, comment 7).

MINIMAL REPRODUCTION
1. File A in album X and an identical copy B in album Y. Only B's path is in
the FilePaths table of the thumbnails DB. This is the normal state: when A is
displayed, its thumbnail is found by hash, so A's path is never stored.
2. Maintenance > Rebuild Thumbnails, "Scan for changed or non-cataloged items"
checked, only album X selected.
3. Result: A's path is now in FilePaths, and B's path is gone, although album Y
was not selected.
Verified on my DB with D:/Photos/2012/2012-Divers/IMG_0967.MP4 and
D:/Photos/iCloud/Photos/IMG_0967.MP4, using this query on thumbnails-digikam.db
before and after step 2:
  SELECT path, thumbId FROM FilePaths WHERE path LIKE '%/IMG_0967.MP4';
Before: only the iCloud path is listed. After: only the 2012-Divers path is
listed.


FULL COLLECTION
Two consecutive full runs: each regenerated ~6,000 videos/RAW files (~4 hours).
The second run gave back the path to 5,949 copies and removed it from 5,572
twins, while the total number of thumbnails stayed the same (565,288). The next
run would do the opposite. It never converges.

EXPECTED
A second run right after the first should find nothing to do, and processing
album X should never touch items of album Y.

CAUSE (v9.1.0 source)
- ThumbsGenerator::calculateAffectedAlbums() treats an item as missing when its
path is not in FilePaths (getFilePathsWithThumbnail()). Thumbnail lookup,
however, uses the uniqueHash first (ThumbnailCreator::loadThumbsDbInfo()).
- ThumbsTask::run() calls deleteThumbnail(path) -> deleteFromDatabase() ->
removeByUniqueHash(). This deletes the Thumbnails row shared by all identical
files, and the delete_thumbnails trigger also removes the twin's FilePaths
entry.
- storeInDatabase() then stores the new thumbnail for the processed path only.

POSSIBLE FIXES
- In "scan only missing" mode, treat an item as having a thumbnail when its
(uniqueHash, fileSize) exists in UniqueHashes. Or just insert the missing
FilePaths row instead of regenerating.
- And/or do not delete by uniqueHash in ThumbsTask when other items share it.

MINOR, SAME FUNCTION
calculateAffectedAlbums() deduplicates with QStringList::contains() for each
path, which is O(n²): about 3-4 minutes of "analysis" for 218k items before any
work starts. A QSet would fix it.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to