Skip to content

Commit

Permalink
Merge pull request #329 from HiSPARC/improve-performance-map
Browse files Browse the repository at this point in the history
Improve performance for retrieving the latest location for a station
  • Loading branch information
153957 authored Apr 12, 2024
2 parents 7ebbe55 + 34fb496 commit c3e716e
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions publicdb/inforecords/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.db.models import Max
from django.utils.text import slugify

from ..histograms.models import Configuration, Summary
from ..histograms.models import Configuration

FIRSTDATE = datetime.date(2004, 1, 1)

Expand Down Expand Up @@ -276,22 +276,17 @@ def latest_location(self, date=None):
if date is None:
date = datetime.date.today()

# Initialize new config with all None values.
config = Configuration()

try:
summaries = Summary.objects.with_config().filter(station=self, date__lte=date).reverse()
for summary in summaries:
try:
config = (
Configuration.objects.filter(summary=summary).exclude(gps_latitude=0, gps_longitude=0).latest()
)
except Configuration.DoesNotExist:
pass
else:
break
except Summary.DoesNotExist:
pass
config = (
Configuration.objects.exclude(
gps_latitude=0,
gps_longitude=0,
timestamp__gt=date,
).filter(summary__station=self).latest()
)
except Configuration.DoesNotExist:
# Initialize new config with all None values.
config = Configuration()

return {
'latitude': (round(config.gps_latitude, 7) if config.gps_latitude is not None else None),
Expand Down

0 comments on commit c3e716e

Please sign in to comment.