Commit 04ba77a3 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Make the KeyCache actually work as cache

KeyCache destroys itself whenever the last reference to it is released.
Since reinitialization of the cache is very expensive if one has a lot
of keys in the key ring, keep a reference on KeyCache for the whole
lifetime of the kernel. This will greatly speed up selection of keys,
e.g. when composing an encrypted message or when configuring the keys
in the identity dialog.

Also set up automatic update of the key cache on changes in the key ring
by watching the GnuPG home directory (as Kleopatra does).
parent ec9efe4c
Pipeline #61963 passed with stage
in 24 minutes and 20 seconds
......@@ -88,6 +88,10 @@ using KMail::MailServiceImpl;
#include <kmime/kmime_headers.h>
#include <kmime/kmime_message.h>
#include <Libkleo/FileSystemWatcher>
#include <Libkleo/GnuPG>
#include <Libkleo/KeyCache>
#include <QDir>
#include <QFileInfo>
#include <QNetworkConfigurationManager>
......@@ -1090,6 +1094,24 @@ static void kmCrashHandler(int sigId)
}
}
namespace
{
auto initKeyCache()
{
using namespace Kleo;
// set up automatic update of the key cache on changes in the key ring
const auto keyCache = KeyCache::mutableInstance();
auto watcher = std::make_shared<FileSystemWatcher>();
watcher->whitelistFiles(gnupgFileWhitelist());
watcher->addPath(gnupgHomeDirectory());
watcher->setDelay(1000);
keyCache->addFileSystemWatcher(watcher);
return KeyCache::instance();
}
}
void KMKernel::init()
{
the_shuttingDown = false;
......@@ -1097,6 +1119,9 @@ void KMKernel::init()
the_firstStart = KMailSettings::self()->firstStart();
KMailSettings::self()->setFirstStart(false);
// keep a reference on the key cache to avoid expensive reinitialization on each use
mKeyCache = initKeyCache();
the_undoStack = new KMail::UndoStack(20);
the_msgSender = new MessageComposer::AkonadiSender;
......
......@@ -17,6 +17,8 @@
#include <Libkdepim/ProgressManager>
#include <MessageViewer/Viewer>
#include <memory>
#define kmkernel KMKernel::self()
#define kmconfig KMKernel::config()
......@@ -93,6 +95,11 @@ class Provider;
}
#endif
namespace Kleo
{
class KeyCache;
}
class QTimer;
class KMainWindow;
class KMMainWidget;
......@@ -611,6 +618,7 @@ private:
#ifdef WITH_KUSERFEEDBACK
KMailUserFeedbackProvider *mUserFeedbackProvider = nullptr;
#endif
std::shared_ptr<const Kleo::KeyCache> mKeyCache;
bool mDebug = false;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment