Opened 12 years ago

Closed 12 years ago

#18343 closed Cleanup/optimization (fixed)

Refactor deferred model implementation

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are a couple of places in the deferred model implementation which needed cleanup.

  • in models/query_utils.py:
    1. the attribute loaded is dead code.
    2. the weak_ref to model isn't needed.
    3. improve the handling of inheritance primary key cases (if parent_ptr_id is already fetched, then assessing pk should not generate any database queries, as parent_ptr_id already contains the value).
  • in models/base.py:
    1. Model.__reduce__ contained a dead variable, and stupid logic using that dead variable.
  • a minor cleanup to tests/modeltests/field_subclassing/tests.py to spot errors earlier if they happen

The work is tracked in branch defer_inheritance_pk, I will create a pull request soon.

Change History (2)

comment:2 by Anssi Kääriäinen <akaariai@…>, 12 years ago

Resolution: fixed
Status: newclosed

In [a8a81aae20a81e012fddc24f3ede556501af64a2]:

Fixed #18343 -- Cleaned up deferred model implementation

Generic cleanup and dead code removal in deferred model field loading
and model.reduce().

Also fixed an issue where if an inherited model with a parent field
chain parent_ptr_id -> id would be deferred loaded, then accessing
the id field caused caused a database query, even if the id field's
value is already loaded in the parent_ptr_id field.

Note: See TracTickets for help on using tickets.
Back to Top