Commit 61ae4984 authored by David Faure's avatar David Faure

Speed up NotificationSubscriber::acceptsItemNotification

Hotspot spotted a lot of time spent resolving mimetype aliases
while processing notifications
http://www.davidfaure.fr/2020/qmime_alias.png

We might as well resolve to canonical aliases upfront,
setting up subscriptions happens a lot less than actual notifications.
parent c1359d48
Pipeline #29953 passed with stage
in 32 minutes and 19 seconds
...@@ -22,8 +22,6 @@ using namespace Akonadi; ...@@ -22,8 +22,6 @@ using namespace Akonadi;
using namespace Akonadi::Server; using namespace Akonadi::Server;
using namespace AkRanges; using namespace AkRanges;
QMimeDatabase NotificationSubscriber::sMimeDatabase;
#define TRACE_NTF(x) #define TRACE_NTF(x)
//#define TRACE_NTF(x) qCDebug(AKONADISERVER_LOG) << mSubscriber << x //#define TRACE_NTF(x) qCDebug(AKONADISERVER_LOG) << mSubscriber << x
...@@ -176,6 +174,18 @@ void NotificationSubscriber::registerSubscriber(const Protocol::CreateSubscripti ...@@ -176,6 +174,18 @@ void NotificationSubscriber::registerSubscriber(const Protocol::CreateSubscripti
mManager->slotNotify({ changeNtf }); mManager->slotNotify({ changeNtf });
} }
static QStringList canonicalMimeTypes(const QStringList &mimes)
{
static QMimeDatabase sMimeDatabase;
QStringList ret;
ret.reserve(mimes.count());
auto canonicalMime = [](const QString &mime) {
return sMimeDatabase.mimeTypeForName(mime).name();
};
std::transform(mimes.begin(), mimes.end(), std::back_inserter(ret), canonicalMime);
return ret;
}
void NotificationSubscriber::modifySubscription(const Protocol::ModifySubscriptionCommand &command) void NotificationSubscriber::modifySubscription(const Protocol::ModifySubscriptionCommand &command)
{ {
QMutexLocker locker(&mLock); QMutexLocker locker(&mLock);
...@@ -230,10 +240,10 @@ void NotificationSubscriber::modifySubscription(const Protocol::ModifySubscripti ...@@ -230,10 +240,10 @@ void NotificationSubscriber::modifySubscription(const Protocol::ModifySubscripti
REMOVE(mMonitoredResources, command.stopMonitoringResources()) REMOVE(mMonitoredResources, command.stopMonitoringResources())
} }
if (START_MONITORING(MimeTypes)) { if (START_MONITORING(MimeTypes)) {
APPEND(mMonitoredMimeTypes, command.startMonitoringMimeTypes()) APPEND(mMonitoredMimeTypes, canonicalMimeTypes(command.startMonitoringMimeTypes()))
} }
if (STOP_MONITORING(MimeTypes)) { if (STOP_MONITORING(MimeTypes)) {
REMOVE(mMonitoredMimeTypes, command.stopMonitoringMimeTypes()) REMOVE(mMonitoredMimeTypes, canonicalMimeTypes(command.stopMonitoringMimeTypes()))
} }
if (START_MONITORING(Sessions)) { if (START_MONITORING(Sessions)) {
APPEND(mIgnoredSessions, command.startIgnoringSessions()) APPEND(mIgnoredSessions, command.startIgnoringSessions())
...@@ -341,17 +351,7 @@ bool NotificationSubscriber::isCollectionMonitored(Entity::Id id) const ...@@ -341,17 +351,7 @@ bool NotificationSubscriber::isCollectionMonitored(Entity::Id id) const
bool NotificationSubscriber::isMimeTypeMonitored(const QString &mimeType) const bool NotificationSubscriber::isMimeTypeMonitored(const QString &mimeType) const
{ {
// Assumes mLock being locked by caller // Assumes mLock being locked by caller
return mMonitoredMimeTypes.contains(mimeType);
const QMimeType mt = sMimeDatabase.mimeTypeForName(mimeType);
if (mMonitoredMimeTypes.contains(mimeType)) {
return true;
}
const QStringList lst = mt.aliases();
return std::any_of(lst.cbegin(), lst.cend(),
[this](const auto &mt) {
return mMonitoredMimeTypes.contains(mt);
});
} }
bool NotificationSubscriber::isMoveDestinationResourceMonitored(const Protocol::ItemChangeNotification &msg) const bool NotificationSubscriber::isMoveDestinationResourceMonitored(const Protocol::ItemChangeNotification &msg) const
......
...@@ -101,8 +101,6 @@ protected: ...@@ -101,8 +101,6 @@ protected:
bool mAllMonitored; bool mAllMonitored;
bool mExclusive; bool mExclusive;
bool mNotificationDebugging; bool mNotificationDebugging;
static QMimeDatabase sMimeDatabase;
}; };
} // namespace Server } // namespace Server
......
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