#22885: Make Query.set_limits a setter
----------------------------------------------+--------------------
     Reporter:  jorgecarleitao                |      Owner:  nobody
         Type:  Cleanup/optimization          |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  master
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 `Query.set_limits(low=None, high=None)` is used to create LIMIT low OFFSET
 high - low.

 However, as pointed out in [https://groups.google.com/d/msg/django-
 developers/oqgtvFE5y84/gZK6ccOmjRcJ this thread], it *adds* to the limits
 and doesn't *set* the limits.

 Since `Query` is responsible for storing the SQL expression to be
 generated, I propose `Query.set_limits` to be the interface to set the
 limits of the query, and make QuerySet responsible for adding the limits
 if required. I.e. I propose that `set_limits` overrides the previous
 limits. In particular the following becomes equivalent:

 {{{
 Query.set_limits(a, b).set_limits(c, d)
 Query.set_limits(c, b)
 }}}

 Currently this method is used in:

 * `QuerySet.__getitem__`,
 * `QuerySet._earliest_or_latest` (calls `clone.query.set_limits(high=1)`)
 * `Query.has_results` (calls `clone.set_limits(high=1)`)

 and `QuerySet` doesn't seem to be using the add part anyway: neither
 `_earliest_or_latest` (i.e. the methods that use it) nor `__getitem__`
 return a new `QuerySet`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22885>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/057.07196ceb79ca06d5e5a23f0a1d4a909c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to