Skip to content

Commit 59779e4

Browse files
committed
OpenConceptLab/ocl_issues#949 | Source/collection last child updated at | using max query
1 parent 7084c2e commit 59779e4

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

core/common/models.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.core.exceptions import ValidationError
66
from django.core.validators import RegexValidator
77
from django.db import models, IntegrityError
8-
from django.db.models import Value, Q
8+
from django.db.models import Value, Q, Max
99
from django.db.models.expressions import CombinedExpression, F
1010
from django.utils import timezone
1111
from django.utils.functional import cached_property
@@ -362,20 +362,11 @@ def active_mappings(self):
362362

363363
@property
364364
def last_concept_update(self):
365-
# Use 'values_list' instead of 'first' so as not load any concepts...
366-
updated_at = self.concepts.order_by('-updated_at').values_list('updated_at', flat=True)[:1]
367-
if updated_at:
368-
return updated_at[0]
369-
return None
365+
return get(self.concepts.aggregate(max_updated_at=Max('updated_at')), 'max_updated_at', None)
370366

371367
@property
372368
def last_mapping_update(self):
373-
# Use 'values_list' instead of 'first' so as not load any mappings...
374-
updated_at = self.mappings.order_by('-updated_at').values_list('updated_at', flat=True)[:1]
375-
if updated_at:
376-
return updated_at[0]
377-
378-
return None
369+
return get(self.mappings.aggregate(max_updated_at=Max('updated_at')), 'max_updated_at', None)
379370

380371
@property
381372
def last_child_update(self):

0 commit comments

Comments
 (0)