Opened 4 years ago

Closed 4 years ago

#31706 closed Cleanup/optimization (fixed)

Removed unnecessary getattr() call in FileDescriptor.__get__().

Reported by: Sultan Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

To retrieve a deferred model attributes, the __get__ method is called twice. This is because it uses the getattr() function, which in turn causes the __get__ method to be called again.

To prevent this unnecessary call, we can simply delete it (since at that moment the instance dict already contains the reloaded value). This reduces the number of method calls.

Change History (2)

comment:1 by Tim Graham, 4 years ago

Triage Stage: UnreviewedReady for checkin

comment:2 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: newclosed

In 6b25d24a:

Fixed #31706 -- Removed unnecessary getattr() call in FileDescriptor.get().

refresh_from_db() loads fields values.

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