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 2020-01-30 21:09:29 +01:00 committed by Jonathan White
parent a81c6469a8
commit c427000184
2 changed files with 5 additions and 11 deletions

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;
}

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;
};