-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Reload the data source when a dependency layer is changed #37475
Conversation
Isn't this supposed to be handled by setting Dependencies in Layer Properties? |
It is, but it was not doing the job, because if there is a WFS layer, it stays cached. This is what I mean with "A is dependent on layer B". Actually the whole PR is about calling https://github.com/qgis/QGIS/pull/37475/files#diff-106be592650b55ccae79c83eecd15cebR5328 automatically. |
I'm afraid that triggering a reloadData for all type of provider (including the one who does not have cache) every time a dependency has changed will generate an extra read from the provider.
if B is modified, and a dependency is defined between A et B, both will fire the dataChanged. Would not be better to invalidate the cache like it's done here for instance? |
Well, isn't it all what dependencies are about? If they are dependent, they need to be reloaded, or am I missing something?
WFS provider doesn't use |
@3nids Since for other types of vector layers the dependency is allready handled by the four existing signals, |
IIRC, the real point of data dependencies is to refresh the index cache so your snapping information are up to update. When dataChanged is fired, index is rebuilt and data are read again, so if you force reloadData, I would say it triggers an extra read (on Postgres provider for instance). |
Refreshing the data provider right away causes problems on a layer dependent on itself. In that case two `dataChanged` signals are expected to be emitted when deleting or creating a feature, but as the layer is reloaded, the second `dataChanged` is not emitted.
I will further investigate whether the rest of the providers handle this situation correctly, then probably makes sense to move the solution to be WFS specific. |
Isn't this use case already handled correctly with the four existing signals? The absence of a bug report is not helping here... |
I have checked with the PostgreSQL provider. Reminder, the situation is "A is a view from layer B". There is no need to setup dependencies, once the user changes the extent, either by panning or zooming, the view is reloaded from the data source. AFAIK, all the providers reread from the dataSource. |
How things work so far, without dependencies:
How things work so far, with dependencies:
If we add the suggested commit signal, an extra re-read will be issued between steps 5 and 6. I can't see what is not working as it should, that's why I say it's probably a WFS issue needing a WFS solution. |
How does that exactly happen so far? |
For each of the dependent layers, ie layer B, the following signals: QGIS/src/core/qgsvectorlayer.cpp Lines 5371 to 5381 in 7b2dc6e
are connected to layer A's. I think emitDataChanged eventually refreshes the attribute table and triggerRepaint the canvas. I am not familiar with the code but AFAICT it seems to work.
|
The interesting part is what dataChanged is then connected to. If it's |
Wouldn't the other signals need to be replaced so that only a single reload is triggered? Maybe ask @mhugo 's opinion who introduced the feature? |
Maybe. Not sure without looking deeper into this or getting more information. To keep the scope, and just by digesting information from this PR:
Did I miss something? |
If you do so, if A depends on B, and B is modified
So B is read twice, no? For Postgres, it's not a problem because the data is not really read again, so data will be read only once. It's the same for Ogr provider and Oracle don't even implement the reload. I'm don't know about other providers, but in the end maybe calling reload doesn't hurt. |
This will not "reload", it will just invalidate caches. Since there is no "main cache" in QGIS it also cannot really "reload" the data anywhere.
Add to that that repaints are not done "right now" but scheduled, so even if in a single event loop run 5 repaints are requested, only 1 will be executed. Possibly it's more a confusion of "reload" being a bad name and "invalidateCaches" would be better. |
Indeed, and the documentation says it all
So, +1 on calling reloadData |
So in the end we can merge this fix it as it is? Should we move forward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Waiting for a bit if there are some final considerations and if nothing is brought up will merge soon.
Thanks everyone for the work and review!
I'm fine with this too, thanks for this work |
Given layers A and B:
Without the fix, whenever one edits layer B, layer A does not get it's cache invalidated. Because A is a view from B, it means one can modify/create/delete a feature in layer B, but it will not appear in layer A.
Bonus fix:
the toggle edit button on relation editor widget easily get's unsyncronized with the rest of the buttons. If you click on the button when there are changes in the relation and then choose
Cancel
on the dialog, the button wrongly toggles its state, while the rest of the buttons remain enabled. E.g. toggle edit is toggled to false, but the button "Add new row" is enabled, or vice versa.