Skip to content

Commit

Permalink
fix(comparison): ignored pairs were very slow, now fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
theophanemayaud committed Nov 12, 2023
1 parent a7d4749 commit 50b6911
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions QtProject/app/comparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions QtProject/app/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) "
");"
));

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 50b6911

Please sign in to comment.