From 50b6911653253340dc8706e693c8f6aec96694d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophanee=20Mayaud?= Date: Sun, 12 Nov 2023 10:44:11 +0100 Subject: [PATCH] fix(comparison): ignored pairs were very slow, now fixed --- QtProject/app/comparison.cpp | 12 +++++++----- QtProject/app/db.cpp | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/QtProject/app/comparison.cpp b/QtProject/app/comparison.cpp index 1024526..bfbe05a 100644 --- a/QtProject/app/comparison.cpp +++ b/QtProject/app/comparison.cpp @@ -197,10 +197,6 @@ bool Comparison::bothVideosMatch(const Video *left, const Video *right) return theyMatch; } - // check if pair is flagged as not dupplicate in DB - if(Db(_prefs.cacheFilePathName).isPairToIgnore(left->_filePathName, right->_filePathName)) - return false; - _phashSimilarity = 0; const int hashes = _prefs._thumbnails == cutEnds? 2 : 1; @@ -222,7 +218,13 @@ bool Comparison::bothVideosMatch(const Video *left, const Video *right) if(theyMatch) //if cutEnds mode: first comparison matched already, skip second break; } - return theyMatch; + if(!theyMatch) + return false; + // check if pair is flagged as not dupplicate in DB. DB is very slow so only do this after all checks + else if(Db(_prefs.cacheFilePathName).isPairToIgnore(left->_filePathName, right->_filePathName)) + return false; + + return true; } int Comparison::phashSimilarity(const Video *left, const Video *right, const int &nthHash) diff --git a/QtProject/app/db.cpp b/QtProject/app/db.cpp index 72183ff..83ec4ba 100644 --- a/QtProject/app/db.cpp +++ b/QtProject/app/db.cpp @@ -151,12 +151,12 @@ void Db::createTables(QSqlDatabase db, const QString appVersion) query.exec(QStringLiteral( "CREATE TABLE IF NOT EXISTS " "ignored_pairs (" - "pair_id INTEGER PRIMARY KEY AUTOINCREMENT, " "pathName1 TEXT NOT NULL, " "pathName2 TEXT NOT NULL, " "FOREIGN KEY (pathName1) REFERENCES metadata(id), " "FOREIGN KEY (pathName2) REFERENCES metadata(id), " "UNIQUE (pathName1, pathName2) " + "PRIMARY KEY (pathName1, pathName2) " ");" )); @@ -420,9 +420,10 @@ bool Db::isPairToIgnore(const QString filePathName1, const QString filePathName2 "SELECT * " "FROM ignored_pairs " "WHERE " - "(pathName1=:filePathName1 AND pathName2=:filePathName2) " + "(pathName1 = :filePathName1 AND pathName2 = :filePathName2) " "OR " - "(pathName1=:filePathName2 AND pathName2=:filePathName1);" + "(pathName1 = :filePathName2 AND pathName2 = :filePathName1) " + "LIMIT 1;" ); query.bindValue(":filePathName1", filePathName1); query.bindValue(":filePathName2", filePathName2);