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

Reduced queries in full clean #143

Merged
merged 2 commits into from
Sep 29, 2020
Merged

Conversation

sjamaan
Copy link
Contributor

@sjamaan sjamaan commented Sep 1, 2020

This depends on #141 so please review that first (or close it and merge this one)

Peter Bex added 2 commits August 31, 2020 14:43
At least, for Binder models this is the case.  All models managed by
Binder views should inherit from BinderModel, and if not, the user
should code validation error checking in _store().

In all our projects we use django-fullclean because being able to
accidentally save invalid models is a huge mind fuck.  Thus, it is
pointless to call full_clean() in our views, as it means we'll be
running potentially expensive validations twice.  For example,
relation fields check that the foreign relation exists, which requires
a query per relation field.

It is technically a breaking change, but for most projects this will
be a non-issue.  The test suite of Boekestijn passed except for one
test which was specifically for its User view, which uses a non-Binder
model.  This was relatively easy to convert to use a full_clean() in
its _store() method.
This leverages our custom full_clean implementation (#141) in
combination with the LoadedValues mixin.  This allows us to know when
a value did not change and avoid validating the foreign key just
before save, because the foreign key was fine as it was stored, so it
cannot suddenly become invalid.

For complex models with many relations or which are saved a lot, this
makes a big difference, as the reduced number of queries can make
things quite a bit more efficient.
@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2020

Codecov Report

Merging #143 into master will decrease coverage by 0.10%.
The diff coverage is 83.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #143      +/-   ##
==========================================
- Coverage   78.19%   78.09%   -0.11%     
==========================================
  Files          24       24              
  Lines        3252     3268      +16     
==========================================
+ Hits         2543     2552       +9     
- Misses        709      716       +7     
Impacted Files Coverage Δ
binder/views.py 84.42% <64.70%> (-0.35%) ⬇️
binder/models.py 79.38% <90.90%> (+1.16%) ⬆️
binder/plugins/loaded_values.py 83.63% <100.00%> (-3.87%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 659d0bf...dd489f6. Read the comment docs.

@daanvdk daanvdk merged commit a825d90 into master Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants