Commit cf76b3c3 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Use some akRanges in the Server

parent 2e8819b6
......@@ -27,6 +27,7 @@
#include "storage/collectionstatistics.h"
#include "handlerhelper.h"
#include <shared/akranges.h>
#include <private/standarddirs_p.h>
#include <private/scope_p.h>
......@@ -189,18 +190,18 @@ void NotificationManager::emitPendingNotifications()
}
if (mDebugNotifications == 0) {
for (NotificationSubscriber *subscriber : qAsConst(mSubscribers)) {
if (subscriber) {
mSubscribers
| filter(IsNotNull)
| forEach([this](const auto &subscriber) {
mNotifyThreadPool->start(new NotifyRunnable(subscriber, mNotifications));
}
}
});
} else {
// When debugging notification we have to use a non-threaded approach
// so that we can work with return value of notify()
for (const auto &notification : qAsConst(mNotifications)) {
QVector<QByteArray> listeners;
for (NotificationSubscriber *subscriber : qAsConst(mSubscribers)) {
if (subscriber && subscriber->notify(notification)) {
if (subscriber && subscriber->notify(notification)) {
listeners.push_back(subscriber->subscriber());
}
}
......@@ -219,9 +220,9 @@ void NotificationManager::emitDebugNotification(const Protocol::ChangeNotificati
debugNtf->setNotification(ntf);
debugNtf->setListeners(listeners);
debugNtf->setTimestamp(QDateTime::currentMSecsSinceEpoch());
for (NotificationSubscriber *subscriber : qAsConst(mSubscribers)) {
if (subscriber) {
mNotifyThreadPool->start(new NotifyRunnable(subscriber, { debugNtf }));
}
}
mSubscribers
| filter(IsNotNull)
| forEach([this, &debugNtf](const auto &subscriber) {
mNotifyThreadPool->start(new NotifyRunnable(subscriber, {debugNtf}));
});
}
......@@ -27,6 +27,7 @@
#include <QLocalSocket>
#include <QPointer>
#include <shared/akranges.h>
#include <private/protocol_p.h>
#include <private/datastream_p_p.h>
#include <private/protocol_exception_p.h>
......@@ -162,10 +163,9 @@ void NotificationSubscriber::disconnectSubscriber()
if (mCollectionFetchScope.includeStatistics()) {
cfs->setFetchStatistics(false);
}
const auto attrs = mCollectionFetchScope.attributes();
for (const auto &attr : attrs) {
cfs->removeAttribute(attr);
}
mCollectionFetchScope.attributes() | forEach([&cfs](const auto &attr) {
cfs->removeAttribute(attr);
});
cfs->removeSubscriber();
auto tfs = mManager->tagFetchScope();
......@@ -284,14 +284,13 @@ void NotificationSubscriber::modifySubscription(const Protocol::ModifySubscripti
// Did the caller just subscribed to subscription changes?
if (command.startMonitoringTypes().contains(Protocol::ModifySubscriptionCommand::SubscriptionChanges)) {
// If yes, then send them list of all existing subscribers
Q_FOREACH (const NotificationSubscriber *subscriber, mManager->mSubscribers) {
// Send them back to caller
if (subscriber) {
mManager->mSubscribers
| filter(IsNotNull)
| forEach([this](const auto &subscriber) {
QMetaObject::invokeMethod(this, "notify", Qt::QueuedConnection,
Q_ARG(Akonadi::Protocol::ChangeNotificationPtr,
subscriber->toChangeNotification()));
}
}
subscriber->toChangeNotification()));
});
}
if (command.startMonitoringTypes().contains(Protocol::ModifySubscriptionCommand::ChangeNotifications)) {
if (!mNotificationDebugging) {
......@@ -365,13 +364,10 @@ bool NotificationSubscriber::isMimeTypeMonitored(const QString &mimeType) const
}
const QStringList lst = mt.aliases();
for (const QString &alias : lst) {
if (mMonitoredMimeTypes.contains(alias)) {
return true;
}
}
return false;
return std::any_of(lst.cbegin(), lst.cend(),
[this](const auto &mt) {
return mMonitoredMimeTypes.contains(mt);
});
}
bool NotificationSubscriber::isMoveDestinationResourceMonitored(const Protocol::ItemChangeNotification &msg) const
......
......@@ -23,6 +23,7 @@
#include "storage/transaction.h"
#include "resourcemanageradaptor.h"
#include <shared/akranges.h>
#include <private/capabilities_p.h>
#include <QDBusConnection>
......@@ -58,15 +59,12 @@ void ResourceManager::addResourceInstance(const QString &name, const QStringList
void ResourceManager::removeResourceInstance(const QString &name)
{
DataStore *db = DataStore::self();
// remove items and collections
Resource resource = Resource::retrieveByName(name);
if (resource.isValid()) {
const QVector<Collection> collections = resource.collections();
for (/*sic!*/ Collection collection : collections) {
db->cleanupCollection(collection);
}
resource.collections() | forEach([](Collection col) {
DataStore::self()->cleanupCollection(col);
});
// remove resource
resource.remove();
......@@ -75,13 +73,9 @@ void ResourceManager::removeResourceInstance(const QString &name)
QStringList ResourceManager::resourceInstances() const
{
QStringList result;
const auto resources = Resource::retrieveAll();
result.reserve(resources.size());
for (const Resource &res : resources) {
result.append(res.name());
}
return result;
return Resource::retrieveAll()
| transform(&Resource::name)
| toQList;
}
ResourceManager *ResourceManager::self()
......
......@@ -111,6 +111,8 @@ auto invoke(Fun &&fun, Args && ... args)
return detail::invoke(std::forward<Fun>(fun), std::forward<Args>(args) ...);
}
static const auto IsNull = [](auto ptr) { return !(bool)ptr; };
static const auto IsNotNull = [](auto ptr) { return (bool)ptr; };
} // namespace Akonadi
......
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