diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 22:40:05 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 22:40:05 +0100 |
commit | 2c80424031c195333cfa6785ea7ab57dc9613fa3 (patch) | |
tree | 9e4a0bc1dc83224aae67661a74a85dabe1aeca98 /common/facade.cpp | |
parent | 2dfa85df6cf46dc2a5ee0c6bf69aa030b19a8435 (diff) | |
download | sink-2c80424031c195333cfa6785ea7ab57dc9613fa3.tar.gz sink-2c80424031c195333cfa6785ea7ab57dc9613fa3.zip |
Cache ResourceAccess instances.
We want one connection per application per resource instance.
With this change the connection is maintained for the lifetime of the
client process (it should probably time out instead), but we at least
avoid creating a connection per operation/query, which results in
a significant performance boost (~10% for reading, 90% for writing in
dummyresourcebenchmark).
Diffstat (limited to 'common/facade.cpp')
-rw-r--r-- | common/facade.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/common/facade.cpp b/common/facade.cpp index 1d6b9a7..ab41f96 100644 --- a/common/facade.cpp +++ b/common/facade.cpp | |||
@@ -28,6 +28,27 @@ | |||
28 | 28 | ||
29 | using namespace Akonadi2; | 29 | using namespace Akonadi2; |
30 | 30 | ||
31 | class ResourceAccessFactory { | ||
32 | public: | ||
33 | static ResourceAccessFactory &instance() | ||
34 | { | ||
35 | static ResourceAccessFactory *instance = 0; | ||
36 | if (!instance) { | ||
37 | instance = new ResourceAccessFactory; | ||
38 | } | ||
39 | return *instance; | ||
40 | } | ||
41 | |||
42 | Akonadi2::ResourceAccess::Ptr getAccess(const QByteArray &instanceIdentifier) | ||
43 | { | ||
44 | if (!mCache.contains(instanceIdentifier)) { | ||
45 | mCache.insert(instanceIdentifier, Akonadi2::ResourceAccess::Ptr::create(instanceIdentifier)); | ||
46 | } | ||
47 | return mCache.value(instanceIdentifier); | ||
48 | } | ||
49 | |||
50 | QHash<QByteArray, Akonadi2::ResourceAccess::Ptr> mCache; | ||
51 | }; | ||
31 | 52 | ||
32 | template<class DomainType> | 53 | template<class DomainType> |
33 | GenericFacade<DomainType>::GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory , const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess) | 54 | GenericFacade<DomainType>::GenericFacade(const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory , const QSharedPointer<Akonadi2::ResourceAccessInterface> resourceAccess) |
@@ -37,7 +58,7 @@ GenericFacade<DomainType>::GenericFacade(const QByteArray &resourceIdentifier, c | |||
37 | mResourceInstanceIdentifier(resourceIdentifier) | 58 | mResourceInstanceIdentifier(resourceIdentifier) |
38 | { | 59 | { |
39 | if (!mResourceAccess) { | 60 | if (!mResourceAccess) { |
40 | mResourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(resourceIdentifier); | 61 | mResourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier); |
41 | } | 62 | } |
42 | } | 63 | } |
43 | 64 | ||