#33124: Avoid accessing ConnectionsHandler.__getitem__ in a few more places 
until
it's strictly necessary.
-------------------------------------+-------------------------------------
               Reporter:  Keryn      |          Owner:  Keryn Knight
  Knight                             |
                   Type:             |         Status:  assigned
  Cleanup/optimization               |
              Component:  Database   |        Version:  dev
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Follows on from #33025.

 Most of the codebase does the correct thing as far as I can see,
 preferring `conn(ection) = connections[alias]` and holding a reference to
 that, when it's used multiple times. Most of the codebase also has
 touching `connections[alias]` as the last component in `if` branches etc
 too, so that short circuiting can occur to avoid touching the `Local`.

 There's a few places where that isn't the case though. eg:
 {{{
 empty_strings_as_null =
 connections[db].features.interprets_empty_strings_as_nulls
 ...
 if val is None or (val == '' and empty_strings_as_null):
 }}}
 or
 {{{
 can_ignore_conflicts = (
     connections[db].features.supports_ignore_conflicts and
     self.through._meta.auto_created is not False
 )
 }}}
 or
 {{{
 compiler = connections[db].ops.compiler('SQLCompiler')(
     self.query, connections[db], db
 )
 }}}

 Whilst I've not gone to the effort of benchmarking each of them, each of
 them has the possibility to slightly improve things, I think.

 I'll be pushing a PR shortly with a bunch of commits that cover all of
 those I've found (outside of tests, where things are more gnarly and could
 be tackled separately, if there's an impetus to do so), so that CI can
 prove things work, and so that it can be decided which, if any of them,
 are worth it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33124>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.97106a87d6ef048c62e8aba86ec6b95f%40djangoproject.com.

Reply via email to