mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-03-30 18:08:16 -04:00
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:
parent
a81c6469a8
commit
c427000184
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user