Skip to content

Commit

Permalink
fix: skip details loading for existing MD5 (fix #3140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Apr 28, 2024
1 parent 7303246 commit c6b22e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/src/downloader/image-downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ void ImageDownloader::setBlacklist(Blacklist *blacklist)

void ImageDownloader::save()
{
// We don't need to load the image details of files already in the MD5 list and that should be skipped
const QString md5action = m_profile->md5Action(m_image->md5(), {}).first;
if (md5action == "ignore" && !m_force) {
loadedSave(Image::LoadTagsResult::Ok);
return;
}

// Always load details if the API doesn't provide the file URL in the listing page
const QStringList forcedTokens = m_image->parentSite()->getApis().first()->forcedTokens();
const bool needFileUrl = forcedTokens.contains("*") || forcedTokens.contains("file_url");
Expand Down Expand Up @@ -231,7 +238,7 @@ void ImageDownloader::loadedSave(Image::LoadTagsResult result)
// If we don't need any loading, we can return already
Image::SaveResult res = m_image->preSave(m_temporaryPath, m_size);
if (res != Image::SaveResult::NotLoaded && (res != Image::SaveResult::AlreadyExistsDeletedMd5 || !m_forceExisting)) {
QList<ImageSaveResult> preResult {{ m_temporaryPath, m_size, res }};
QList<ImageSaveResult> preResult {{ m_temporaryPath, m_size, res }}; // TODO(Bionus): this should use the MD5 path if possible

if (res == Image::SaveResult::Saved || res == Image::SaveResult::Copied || res == Image::SaveResult::Moved || res == Image::SaveResult::Shortcut || res == Image::SaveResult::Linked) {
preResult = afterTemporarySave(res);
Expand Down
14 changes: 14 additions & 0 deletions src/lib/tests/src/downloader/image-downloader-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,18 @@ TEST_CASE("ImageDownloader")
settings->remove("ImageSize/maxWidthEnabled");
settings->remove("ImageSize/maxWidth");
}

SECTION("Skip details for existing images")
{
auto img = createImage(profile, site);
ImageDownloader downloader(profile, img, "%copyright%.%ext%", "tests/resources/tmp", 1, false, false, nullptr, true, false);

QList<ImageSaveResult> expected;
expected.append({ QDir::toNativeSeparators("tests/resources/tmp/misc.jpg.tmp"), Image::Size::Full, Image::SaveResult::AlreadyExistsMd5 });

profile->getSettings()->setValue("Save/md5Duplicates", "ignore");
profile->addMd5(img->md5(), "tests/resources/image_1x1.png");

assertDownload(profile, img, &downloader, expected, false);
}
}

0 comments on commit c6b22e2

Please # to comment.