[locations] Tigten up how we finish locations

This commit is contained in:
2024-02-11 00:38:10 -05:00
parent 5651ccb990
commit 36bc1c2e95
2 changed files with 20 additions and 14 deletions

View File

@ -776,21 +776,27 @@ class Scrobble(TimeStampedModel):
.first() .first()
) )
geo_loc_has_not_moved = False moved_location = False
if key == "geo_location" and not cls.has_moved(media, user_id): if key == "geo_location":
# We have a new location, but have not moved from it, # For geo locations, we always only care about our last location
# don't proceed with scrobbling, but update the last GeoLoc scrobble = (
geo_loc_has_not_moved = True cls.objects.filter(
if not scrobble: media_type=cls.MediaType.GEO_LOCATION, user_id=user_id
scrobble = (
cls.objects.filter(
media_type=cls.MediaType.GEO_LOCATION, user_id=user_id
)
.order_by("-timestamp")
.first()
) )
.order_by("-timestamp")
.first()
)
if scrobble and scrobble.media_obj == media:
# If scrobble loc and new loc are identical, we haven't moved
moved_location = False
else:
# We have a new location, but have not moved from it,
# don't proceed with scrobbling, but update the last GeoLoc
moved_location = cls.has_moved(media, user_id)
if scrobble and moved_location:
check_scrobble_for_finish(scrobble, force_finish=True)
if scrobble and (scrobble.can_be_updated or geo_loc_has_not_moved): if scrobble and (scrobble.can_be_updated or not moved_location):
source = scrobble_data["source"] source = scrobble_data["source"]
mtype = media.__class__.__name__ mtype = media.__class__.__name__
logger.info( logger.info(

View File

@ -92,7 +92,7 @@ def check_scrobble_for_finish(
scrobble: "Scrobble", force_to_100=False, force_finish=False scrobble: "Scrobble", force_to_100=False, force_finish=False
) -> None: ) -> None:
completion_percent = scrobble.media_obj.COMPLETION_PERCENT completion_percent = scrobble.media_obj.COMPLETION_PERCENT
if scrobble.media_type == "GeoLocation": if scrobble.media_type == "GeoLocation" and not force_finish:
logger.info( logger.info(
f"{scrobble.id} not complete, GeoLocs are completed when new one is created" f"{scrobble.id} not complete, GeoLocs are completed when new one is created"
) )