[ch140093] Fix subscription/sample filter for datasets #16254
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resources
Context
In the visualizations controller we are paginating the visualizations, and then filtering by subscriptions or samples if we select "Subscriptions" or "Samples" in the dashboard. It means that we will only see the subscribed dataset located in the current page.
The idea would be adding the subscription and sample filters to the rest of
ActiveRecord
filters. This way we would filter, and then we would paginate the result. The way to know if a visualization is a "subscription" or a "sample" is calling to the methodsubscription?
/sample?
. So in this case I'm trying to use those methods toselect
the visualizations with a sample/subscription, get the IDs, and then add awhere
filter by ID (to keep using anActiveRecord::Relation
, in order to not paginate it as an array and avoid potential issues).I understand that it is not the most elegant option and I could use
ActiveRecord
for samples with something similar to the following (not tested):This wouldn't be enough for subscriptions, because there is an additional check: if the user subscription is active. The list of subscriptions is stored in Redis, and we need to check if the
subscription_id
is in the Redis' list, like in https://github.com/CartoDB/db-connectors/blob/master/lib/do_sync_service.rb#L189.But since we are calling anyway the
subscription?
/sample?
method for all visualizations to calculate the DO totals in https://github.com/CartoDB/cartodb/blob/master/app/controllers/carto/api/visualizations_controller.rb#L505-L512, I would say that filtering usingselect
is "safe" (in terms of adding additional load).Changes
Carto::VisualizationQueryFilterer
.