You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if Criteria.and_ / Criteria.or_ would automatically simplify for various simple cases.
This could result in cleaner mongo queries to Pulp. It could potentially result in improved performance in some cases, (although perhaps mongo already does such simplification so that this improvement is negligible.)
Issue Type
Feature Request
Current behavior
Criteria always translates directly into mongo queries when querying to Pulp e.g.
Criteria for and_ and or_ sometimes simplify according to at least these boolean simplification rules:
# single-element AND or OR is equivalent to just the subclause
Criteria.and_([clause1]) => clause1
Criteria.or_([clause1]) => clause1
# True can be removed from any AND or OR with no effect on the result
Criteria.and_([clause1, clause2, Criteria.true()]) => Criteria.and_([clause1, clause2])
Criteria.or_([clause1, clause2, Criteria.true()]) => Criteria.or_([clause1, clause2])
# And above two simplifications should work together
Criteria.and_([clause1, Criteria.true()]) => Criteria.and_([clause1]) => clause1
Use case
The use-case is to enable a natural way of building up elements of a criteria conditionally, without having to pay the cost of mongo queries becoming uglier than needed.
For example, it should be OK for a user of this library to write this:
# start with all repos
repo_crit = Criteria.true()
# restrict by URL if given
if url_filter:
repo_crit = Criteria.and_([repo_crit, Criteria.with_field('relative_url', Matcher.regex(url_filter))])
# restrict by product if given
if product_filter:
repo_crit = Criteria.and_([repo_crit, Criteria.with_field('eng_product_id', Matcher.in_(product_filter))])
# ...and so on
# When we query mongo, it should result in a simple query such as:
{"$and": [{"notes.eng_product": ...}, {"notes.relative_url": ...}]}
# and NOT with nested AND, like:
{"$and": [{}, {"$and": [{"notes.eng_product": ...}, {"$and": {"notes.relative_url": ...}}]}]}
Summary
It would be nice if Criteria.and_ / Criteria.or_ would automatically simplify for various simple cases.
This could result in cleaner mongo queries to Pulp. It could potentially result in improved performance in some cases, (although perhaps mongo already does such simplification so that this improvement is negligible.)
Issue Type
Current behavior
Criteria always translates directly into mongo queries when querying to Pulp e.g.
Desired behavior
Criteria for and_ and or_ sometimes simplify according to at least these boolean simplification rules:
Use case
The use-case is to enable a natural way of building up elements of a criteria conditionally, without having to pay the cost of mongo queries becoming uglier than needed.
For example, it should be OK for a user of this library to write this:
Additional Information
Noticed the use-case in release-engineering/pubtools-pulp#13 (comment).
The text was updated successfully, but these errors were encountered: