[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()
)
geo_loc_has_not_moved = False
if key == "geo_location" and not cls.has_moved(media, user_id):
# We have a new location, but have not moved from it,
# don't proceed with scrobbling, but update the last GeoLoc
geo_loc_has_not_moved = True
if not scrobble:
scrobble = (
cls.objects.filter(
media_type=cls.MediaType.GEO_LOCATION, user_id=user_id
)
.order_by("-timestamp")
.first()
moved_location = False
if key == "geo_location":
# For geo locations, we always only care about our last location
scrobble = (
cls.objects.filter(
media_type=cls.MediaType.GEO_LOCATION, user_id=user_id
)
.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"]
mtype = media.__class__.__name__
logger.info(

View File

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