Remove result cache from the HealthChecker class

The way the class is currently being used, the cache never does
anything (because evaluate is never invoked twice for the same
entry), so according to YAGNI it has to go.

Fixes #551
This commit is contained in:
Wolfram Rösler authored and Jonathan White committed 2020-02-01 09:30:12 -05:00
1 parent a81c6469a8
commit c427000184
2 files changed
+5 -11

No files matched your search

+3 -7
View File
@@ -116,17 +116,13 @@ HealthChecker::HealthChecker(QSharedPointer<Database> db)
* Returns the health of the password in `entry`, considering
* password entropy, re-use, expiration, etc.
*/
QSharedPointer<PasswordHealth> HealthChecker::evaluate(const Entry* entry)
QSharedPointer<PasswordHealth> HealthChecker::evaluate(const Entry* entry) const
{
// Pointer sanity check
if (!entry) {
return {};
}
// Return from cache if we saw it before
if (m_cache.contains(entry->uuid())) {
return m_cache[entry->uuid()];
}
// First analyse the password itself
const auto pwd = entry->password();
auto health = QSharedPointer<PasswordHealth>(new PasswordHealth(pwd));
@@ -184,5 +180,5 @@ QSharedPointer<PasswordHealth> HealthChecker::evaluate(const Entry* entry)
}
// Return the result
return m_cache.insert(entry->uuid(), health).value();
return health;
}
+2 -4
View File
@@ -101,12 +101,10 @@ public:
explicit HealthChecker(QSharedPointer<Database>);
// Get the health status of an entry in the database
QSharedPointer<PasswordHealth> evaluate(const Entry* entry);
QSharedPointer<PasswordHealth> evaluate(const Entry* entry) const;
private:
// Result cache (first=entry UUID)
QHash<QUuid, QSharedPointer<PasswordHealth>> m_cache;
// first = password, second = entries that use it
// To determine password re-use: first = password, second = entries that use it
QHash<QString, QStringList> m_reuse;
};