From c6b22e2baafe7f1c93bafe85734036b3751c987e Mon Sep 17 00:00:00 2001 From: Bionus Date: Sun, 28 Apr 2024 02:33:29 +0200 Subject: [PATCH] fix: skip details loading for existing MD5 (fix #3140) --- src/lib/src/downloader/image-downloader.cpp | 9 ++++++++- .../tests/src/downloader/image-downloader-test.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/lib/src/downloader/image-downloader.cpp b/src/lib/src/downloader/image-downloader.cpp index 6437d0734..b05b9124c 100644 --- a/src/lib/src/downloader/image-downloader.cpp +++ b/src/lib/src/downloader/image-downloader.cpp @@ -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"); @@ -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 preResult {{ m_temporaryPath, m_size, res }}; + QList 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); diff --git a/src/lib/tests/src/downloader/image-downloader-test.cpp b/src/lib/tests/src/downloader/image-downloader-test.cpp index 6282526a0..7b6e416a5 100644 --- a/src/lib/tests/src/downloader/image-downloader-test.cpp +++ b/src/lib/tests/src/downloader/image-downloader-test.cpp @@ -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 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); + } }