From 784bf50c092b6a14e848e92c1b10c2f203d34a1e Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Wed, 17 Apr 2024 14:41:25 +0200 Subject: [PATCH 1/3] Add deprecation warning to `JoinManagerMixin` --- model_utils/managers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/model_utils/managers.py b/model_utils/managers.py index d7134e3..f1bb581 100644 --- a/model_utils/managers.py +++ b/model_utils/managers.py @@ -392,6 +392,11 @@ class JoinManagerMixin: _queryset_class = JoinQueryset def get_queryset(self): + warnings.warn( + "JoinManager and JoinManagerMixin are deprecated. " + "Please use 'JoinQueryset.as_manager()' instead.", + DeprecationWarning + ) return self._queryset_class(model=self.model, using=self._db) From 1ca51a55ed455d7a6cc97dde5e2e49772b5eb7e8 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Wed, 17 Apr 2024 14:44:05 +0200 Subject: [PATCH 2/3] Document deprecation of `JoinManager` in ChangeLog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 34cfd37..e1a3ca3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,8 @@ To be released forward additional arguments to Django - `SplitField` no longer accepts `no_excerpt_field` as a keyword argument - Make `soft` argument to `SoftDeletableModel.delete()` keyword-only +- `JoinManager` and `JoinManagerMixin` have been deprecated; + please use ``JoinQueryset.as_manager()`` instead 4.4.0 (2024-02-10) ------------------ From 441618a790cb90129f580c50c1bf29b48c507dd7 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Wed, 17 Apr 2024 17:28:25 +0200 Subject: [PATCH 3/3] Update manual to explain `JoinQueryset` instead of `JoinManager` --- docs/managers.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/managers.rst b/docs/managers.rst index 54aff0a..c5bb2ce 100644 --- a/docs/managers.rst +++ b/docs/managers.rst @@ -86,11 +86,11 @@ it's safe to use as your default manager for the model. .. _contributed by Jeff Elmore: https://jeffelmore.org/2010/11/11/automatic-downcasting-of-inherited-models-in-django/ -JoinManager ------------ +JoinQueryset +------------ -The ``JoinManager`` will create a temporary table of your current queryset -and join that temporary table with the model of your current queryset. This can +A ``JoinQueryset`` will create a temporary table containing its own query result +and join that temporary table with the model it is querying. This can be advantageous if you have to page through your entire DB and using django's slice mechanism to do that. ``LIMIT .. OFFSET ..`` becomes slower the bigger offset you use. @@ -102,8 +102,9 @@ offset you use. # qs contains 10 objects, and there will be a much smaller performance hit # for paging through all of first 2000 objects. -Alternatively, you can give it a queryset and the manager will create a temporary -table and join that to your current queryset. This can work as a more performant +Alternatively, you can give it another queryset and ``JoinQueryset`` will create +a temporary table containing the result of the given queryset and +join that temporary table to itself. This can work as a more performant alternative to using django's ``__in`` as described in the following (`StackExchange answer`_). @@ -114,6 +115,8 @@ alternative to using django's ``__in`` as described in the following .. _StackExchange answer: https://dba.stackexchange.com/questions/91247/optimizing-a-postgres-query-with-a-large-in +You can create a manager that produces ``JoinQueryset`` instances using ``JoinQueryset.as_manager()``. + .. _QueryManager: QueryManager