Create an LRU cache for linkpreviewers

Create an LRU cache for linkpreviewers to stop the storage growing continuously as new links are made.
This commit is contained in:
James Graham
2024-08-27 08:15:03 +00:00
parent cc7f783b50
commit 6d77ed1e0e
2 changed files with 7 additions and 6 deletions

View File

@@ -9,7 +9,6 @@
#include "controller.h"
#include "jobs/neochatchangepasswordjob.h"
#include "jobs/neochatdeactivateaccountjob.h"
#include "linkpreviewer.h"
#include "neochatconfig.h"
#include "neochatroom.h"
#include "notificationsmanager.h"
@@ -45,6 +44,7 @@ NeoChatConnection::NeoChatConnection(QObject *parent)
: Connection(parent)
, m_threePIdModel(new ThreePIdModel(this))
{
m_linkPreviewers.setMaxCost(20);
connectSignals();
}
@@ -52,6 +52,7 @@ NeoChatConnection::NeoChatConnection(const QUrl &server, QObject *parent)
: Connection(server, parent)
, m_threePIdModel(new ThreePIdModel(this))
{
m_linkPreviewers.setMaxCost(20);
connectSignals();
}
@@ -563,13 +564,13 @@ LinkPreviewer *NeoChatConnection::previewerForLink(const QUrl &link)
return nullptr;
}
auto previewer = m_linkPreviewers.value(link, nullptr);
auto previewer = m_linkPreviewers.object(link);
if (previewer != nullptr) {
return previewer;
}
previewer = new LinkPreviewer(link, this);
m_linkPreviewers[link] = previewer;
m_linkPreviewers.insert(link, previewer);
return previewer;
}