Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty vector layer reload() will never invalidate cache #60154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/core/vector/qgsvectorlayercache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,11 @@ void QgsVectorLayerCache::layerDeleted()

void QgsVectorLayerCache::invalidate()
{
if ( ! mCache.isEmpty() )
{
mCache.clear();
mCacheOrderedKeys.clear();
mCacheUnorderedKeys.clear();
mFullCache = false;
emit invalidated();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep the if condition and just get out the signal firing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I cant' remember exactly but I suspect that part of the speed optimization of my original PR was to not fire the signal when the cache was not changed (because it was already empty) .

The fact here is that there are possibly many side effects when firing a signal and some of these can slow down the application significantly.

I would recommend to explore if are there other ways to fix the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the condition only blocks the signal when it is empty, and the signal is still emitted when it is not empty. Is it feasible to add if(mFullCache)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elpaso That would require then to be able to distinguish between an empty cache because of an empty layer, or an empty cache because cache has not been yet populated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elpaso That would require then to be able to distinguish between an empty cache because of an empty layer, or an empty cache because cache has not been yet populated

Can we do that? Maybe a flag that is flipped the first time the cache is "populated" (even if empty)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or a boolean isLayerEmpty updated when we populate the cache

Copy link
Contributor Author

@hxbb00 hxbb00 Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use mFullCache as a flag? What is the purpose of mFullCache?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mFullCache stands for "all the layer is in the cache".

Maybe we could replace it with an enum on cache state : EMPTY_LAYER, NOT_INITIALIZED, PARTIAL, FULL

}
mCache.clear();
mCacheOrderedKeys.clear();
mCacheUnorderedKeys.clear();
mFullCache = false;
emit invalidated();
}

bool QgsVectorLayerCache::canUseCacheForRequest( const QgsFeatureRequest &featureRequest, QgsFeatureIterator &it )
Expand Down
Loading