Commit 8398a688 authored by Tobias Koenig's avatar Tobias Koenig

Cache the ancestor chain for items from the same collection.

svn path=/trunk/KDE/kdepimlibs/; revision=1186758
parent c9e5fffb
......@@ -79,6 +79,25 @@ QByteArray ProtocolHelper::cachePolicyToByteArray(const CachePolicy & policy)
return rv;
}
void ProtocolHelper::parseAncestorsCached( const QByteArray &data, Entity *entity, Collection::Id parentCollection,
ProtocolHelperValuePool *pool, int start )
{
if ( !pool || parentCollection == -1 ) {
// if no pool or parent collection id is provided we can't cache anything, so continue as usual
parseAncestors( data, entity, start );
return;
}
if ( pool->ancestorCollections.contains( parentCollection ) ) {
// ancestor chain is cached already, so use the cached value
entity->setParentCollection( pool->ancestorCollections.value( parentCollection ) );
} else {
// not cached yet, parse the chain
parseAncestors( data, entity, start );
pool->ancestorCollections.insert( parentCollection, entity->parentCollection() );
}
}
void ProtocolHelper::parseAncestors( const QByteArray &data, Entity *entity, int start )
{
Q_UNUSED( start );
......@@ -355,7 +374,7 @@ void ProtocolHelper::parseItemFetchResult( const QList<QByteArray> &lineTokens,
ImapParser::parseDateTime( lineTokens[i + 1], datetime );
item.setModificationTime( datetime );
} else if ( key == "ANCESTORS" ) {
ProtocolHelper::parseAncestors( lineTokens[i + 1], &item );
ProtocolHelper::parseAncestorsCached( lineTokens[i + 1], &item, cid, valuePool );
} else {
int version = 0;
QByteArray plainKey( key );
......
......@@ -42,6 +42,7 @@ struct ProtocolHelperValuePool
FlagPool flagPool;
MimeTypePool mimeTypePool;
QHash<Collection::Id, Collection> ancestorCollections;
};
/**
......@@ -81,6 +82,14 @@ class ProtocolHelper
*/
static void parseAncestors( const QByteArray &data, Entity *entity, int start = 0 );
/**
Convert a ancestor chain from its protocol representation into an Entity object.
This method allows to pass a @p valuePool which acts as cache, so ancestor paths for the
same @p parentCollection don't have to be parsed twice.
*/
static void parseAncestorsCached( const QByteArray &data, Entity *entity, Collection::Id parentCollection, ProtocolHelperValuePool *valuePool = 0, int start = 0 );
/**
Parse a collection description.
@param data The input data.
......
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