mirror of https://github.com/django/django.git
Refs #28459 -- Improved performance of loading DurationField on SQLite and MySQL.
This commit is contained in:
parent
ef6c680f60
commit
ae1baa7d1d
|
@ -7,7 +7,6 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.db import NotSupportedError, transaction
|
||||
from django.db.backends import utils
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_duration
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
|
||||
|
@ -568,9 +567,7 @@ class BaseDatabaseOperations:
|
|||
|
||||
def convert_durationfield_value(self, value, expression, connection):
|
||||
if value is not None:
|
||||
value = str(decimal.Decimal(value) / decimal.Decimal(1000000))
|
||||
value = parse_duration(value)
|
||||
return value
|
||||
return datetime.timedelta(0, 0, value)
|
||||
|
||||
def check_expression_support(self, expression):
|
||||
"""
|
||||
|
|
|
@ -94,6 +94,12 @@ class Avg(Aggregate):
|
|||
return FloatField()
|
||||
return super()._resolve_output_field()
|
||||
|
||||
def as_mysql(self, compiler, connection):
|
||||
sql, params = super().as_sql(compiler, connection)
|
||||
if self.output_field.get_internal_type() == 'DurationField':
|
||||
sql = 'CAST(%s as SIGNED)' % sql
|
||||
return sql, params
|
||||
|
||||
def as_oracle(self, compiler, connection):
|
||||
if self.output_field.get_internal_type() == 'DurationField':
|
||||
expression = self.get_source_expressions()[0]
|
||||
|
@ -153,6 +159,12 @@ class Sum(Aggregate):
|
|||
function = 'SUM'
|
||||
name = 'Sum'
|
||||
|
||||
def as_mysql(self, compiler, connection):
|
||||
sql, params = super().as_sql(compiler, connection)
|
||||
if self.output_field.get_internal_type() == 'DurationField':
|
||||
sql = 'CAST(%s as SIGNED)' % sql
|
||||
return sql, params
|
||||
|
||||
def as_oracle(self, compiler, connection):
|
||||
if self.output_field.get_internal_type() == 'DurationField':
|
||||
expression = self.get_source_expressions()[0]
|
||||
|
|
Loading…
Reference in New Issue