Ticket #11181: faster-inserts-by-caching-manager.patch

File faster-inserts-by-caching-manager.patch, 1.2 KB (added by novalis, 6 years ago)
  • django/db/models/base.py

     
    455455            pk_set = pk_val is not None
    456456            record_exists = True
    457457            manager = cls._base_manager
     458            if hasattr(cls, '_insert_manager'):
     459                insert_manager = cls._insert_manager
     460            else:
     461                insert_manager = cls._insert_manager = cls._default_manager.extra(select={'a': 1}).values('a').order_by()
     462
    458463            if pk_set:
    459464                # Determine whether a record with the primary key already exists.
    460465                if (force_update or (not force_insert and
    461                         manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by())):
     466                        insert_manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by())):
    462467                    # It does already exist, so do an UPDATE.
    463468                    if force_update or non_pks:
    464469                        values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
Back to Top