Skip to content
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

Optimise owrt checking of double underscore relations #295

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Mar 29, 2023

  1. add failing test for #293

    shuckc committed Mar 29, 2023
    Configuration menu
    Copy the full SHA
    c75b839 View commit details
    Browse the repository at this point in the history
  2. Query ForeignKey id values during load to optimise order_with_respect…

    …_to check during save()
    
    This favours a smaller overall query count over simpler queries.
    
    By adding attributes during evaluation of the queryset, we can store the prior value of
    ForeignKey relations, for the cost of a join for each entry within
    order_with_respect_to (nested joins if LOOKUP_SEPARATOR (__) is used).
    
    The fetched attibutes are not available during OrderedModel.__init__() so we defer creation
    of self._original_wrt_map until save(). Since this reads from attributes it no longer
    causes any additional queries.
    
    This seems to balance correctness in the case of modifying the fields you are ordered
    with respect to, against minimising extra queries during either get() or save()
    operations, and does not require the full related object to be fetched to detect the change.
    shuckc committed Mar 29, 2023
    Configuration menu
    Copy the full SHA
    1b691f8 View commit details
    Browse the repository at this point in the history