Commit 53d1b4c6 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Introduce Config class, disable payload comp. by default

The Config is a global class that allows for run-time tuning
of behaviour of Akonadi clients, like enabling or disabling
payload compression, in future selecting compression algorithm
and compression level and possibly more.

At the same time this disables the payload compression feature
by default (can be enabled via config) as LZMA is too slow and
I failed to implement LZMA in time for 20.12.
parent 9de58ff1
......@@ -18,6 +18,7 @@ set(akonadicore_base_SRCS
changerecorder.cpp
changerecorder_p.cpp
changerecorderjournal.cpp
config.cpp
connection.cpp
collection.cpp
collectionfetchscope.cpp
......
/*
SPDX-FileCopyrightText: 2020 Daniel Vrátil <dvratil@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "config_p.h"
#include "private/instance_p.h"
#include <KSharedConfig>
#include <KConfigGroup>
using namespace Akonadi;
Config Config::sConfig{};
namespace {
QString getConfigName()
{
if (Instance::hasIdentifier()) {
return QStringLiteral("akonadi_%1rc").arg(Instance::identifier());
} else {
return QStringLiteral("akonadirc");
}
}
static constexpr char group_PayloadCompression[] = "PayloadCompression";
// Payload compression
static constexpr char key_PC_Enabled[] = "enabled";
} // namespace
Config::Config()
{
auto config = KSharedConfig::openConfig(getConfigName());
{
const auto group = config->group(group_PayloadCompression);
payloadCompression.enabled = group.readEntry(key_PC_Enabled, payloadCompression.enabled);
}
}
void Config::setConfig(const Config &config)
{
sConfig = config;
}
/*
SPDX-FileCopyrightText: 2020 Daniel Vrátil <dvratil@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef AKONADI_CONFIG_P_H
#define AKONADI_CONFIG_P_H
#include <memory>
namespace Akonadi
{
class Config
{
public:
~Config() = default;
static const Config &get()
{
return sConfig;
}
struct PayloadCompression {
/**
* Whether or not the payload compression feature should be enabled.
* Default is false (currently).
*
* This only disables only compressing the payload. If the feature is disabled,
* Akonadi can still decompress payloads that have been compressed previously.
*/
bool enabled = false;
};
/**
* Configures behavior of the payload compression feature.
*/
PayloadCompression payloadCompression = {};
protected:
explicit Config();
static void setConfig(const Config &config);
private:
static Config sConfig;
};
} // namespace Akonadi
#endif
......@@ -10,6 +10,7 @@
#include "itemserializerplugin.h"
#include "typepluginloader_p.h"
#include "protocolhelper_p.h"
#include "config_p.h"
#include "private/externalpartstorage_p.h"
#include "private/compressionstream_p.h"
......@@ -156,9 +157,13 @@ void ItemSerializer::serialize(const Item &item, const QByteArray &label, QIODev
}
ItemSerializerPlugin *plugin = TypePluginLoader::pluginForMimeTypeAndClass(item.mimeType(), item.availablePayloadMetaTypeIds());
CompressionStream compressor(&data);
compressor.open(QIODevice::WriteOnly);
plugin->serialize(item, label, compressor, version);
if (Config::get().payloadCompression.enabled) {
CompressionStream compressor(&data);
compressor.open(QIODevice::WriteOnly);
plugin->serialize(item, label, compressor, version);
} else {
plugin->serialize(item, label, data, version);
}
}
void ItemSerializer::apply(Item &item, const Item &other)
......
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