Skip to content

Commit

Permalink
postgres provider: avoid additional fetch after all features have alr…
Browse files Browse the repository at this point in the history
…eady been processed
  • Loading branch information
jef-n committed Nov 10, 2015
1 parent 452e61c commit 81bbb82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
, mFetched( 0 )
, mFetchGeometry( false )
, mExpressionCompiled( false )
, mLastFetch( false )
{
if ( !source->mTransactionConnection )
{
Expand Down Expand Up @@ -119,7 +120,7 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature& feature )
if ( mClosed )
return false;

if ( mFeatureQueue.empty() )
if ( mFeatureQueue.empty() && !mLastFetch )
{
QString fetch = QString( "FETCH FORWARD %1 FROM %2" ).arg( mFeatureQueueSize ).arg( mCursorName );
QgsDebugMsgLevel( QString( "fetching %1 features." ).arg( mFeatureQueueSize ), 4 );
Expand All @@ -145,6 +146,8 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature& feature )
if ( rows == 0 )
continue;

mLastFetch = rows < mFeatureQueueSize;

for ( int row = 0; row < rows; row++ )
{
mFeatureQueue.enqueue( QgsFeature() );
Expand Down Expand Up @@ -323,7 +326,6 @@ QString QgsPostgresFeatureIterator::whereClauseRect()
bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
{
mFetchGeometry = !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) && !mSource->mGeometryColumn.isNull();

#if 0
// TODO: check that all field indexes exist
if ( !hasAllFields )
Expand Down Expand Up @@ -432,6 +434,7 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
return false;
}

mLastFetch = false;
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class QgsPostgresFeatureIterator : public QgsAbstractFeatureIteratorFromSource<Q
virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;

bool mExpressionCompiled;
bool mLastFetch;
};

#endif // QGSPOSTGRESFEATUREITERATOR_H

0 comments on commit 81bbb82

Please sign in to comment.