Commit 09d52e45 authored by Kevin Krammer's avatar Kevin Krammer Committed by Stephen Kelly
Browse files

Make ETM fetch empty collections at least once

When collections are empty because they have just been created
(synchronizeCollectionTree or equivalent operation), an application
using EntityTreeModel will not fetch their contents, assuming they
are truly empty (contain no items). This is done for optimization

This patch make ETM only skip collections which are known to be
empty. We can't just check the statistics for the optimization
because the statistics will report zero until something is requested
if the resource simply has not been sync'd yet.

BUG: 271913
REVIEW: 101844
parent 9be97347
......@@ -507,6 +507,10 @@ void EntityTreeModelPrivate::itemsFetched( const Collection::Id collectionId, co
Q_ASSERT( collection.isValid() );
// if there are any items at all, remove from set of collections known to be empty
if ( !items.isEmpty() )
m_collectionsWithoutItems.remove( collectionId );
foreach ( const Item &item, items ) {
if ( isHidden( item ) )
......@@ -943,6 +947,13 @@ void EntityTreeModelPrivate::monitoredCollectionStatisticsChanged( Akonadi::Coll
m_collections[ id ].setStatistics( statistics );
// if the item count becomes 0, add to set of collections we know to be empty
// otherwise remove if in there
if ( statistics.count() == 0 )
m_collectionsWithoutItems.insert( id );
m_collectionsWithoutItems.remove( id );
if ( !m_showRootCollection && id == )
// If the root of the model is not Collection::root it might be modified.
// But it doesn't exist in the accessible model structure, so we need to early return
......@@ -1619,6 +1630,7 @@ void EntityTreeModelPrivate::endResetModel()
job->disconnect( q );
foreach ( const QList<Node*> &list, m_childEntities )
......@@ -1719,7 +1731,7 @@ bool EntityTreeModelPrivate::canFetchMore( const QModelIndex & parent ) const
return false;
// Collections which contain no items at all can't contain more
if ( m_collections[colId].statistics().count() == 0 )
if ( m_collectionsWithoutItems.contains( colId ) )
return false;
// Don't start the same job multiple times.
......@@ -145,6 +145,7 @@ public:
QHash<Entity::Id, Item> m_items;
QHash<Collection::Id, QList<Node*> > m_childEntities;
QSet<Collection::Id> m_populatedCols;
QSet<Collection::Id> m_collectionsWithoutItems;
QVector<Entity::Id> m_pendingCutItems;
QVector<Entity::Id> m_pendingCutCollections;
Supports Markdown
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