[books] Calculate page data on scrobble save
All checks were successful
build & deploy / test (push) Successful in 1m45s
build & deploy / build-and-deploy (push) Successful in 28s

This commit is contained in:
2026-05-19 22:54:06 -04:00
parent 217e2443e2
commit db5b673cd5

View File

@ -571,6 +571,8 @@ class Scrobble(TimeStampedModel):
return reverse("scrobbles:finish", kwargs={"uuid": self.uuid}) return reverse("scrobbles:finish", kwargs={"uuid": self.uuid})
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
class_name = self.media_obj.__class__.__name__
if not self.uuid: if not self.uuid:
self.uuid = uuid4() self.uuid = uuid4()
@ -593,6 +595,9 @@ class Scrobble(TimeStampedModel):
self.stop_timestamp - self.timestamp self.stop_timestamp - self.timestamp
).seconds ).seconds
if class_name == "Book":
self.calculate_reading_stats(commit=False)
if ( if (
self.log self.log
and isinstance(self.log, dict) and isinstance(self.log, dict)
@ -600,16 +605,14 @@ class Scrobble(TimeStampedModel):
and self.log.get("page_end") is not None and self.log.get("page_end") is not None
and "pages_read" not in self.log and "pages_read" not in self.log
): ):
self.log["pages_read"] = ( self.log["pages_read"] = self.log["page_end"] - self.log["page_start"] + 1
self.log["page_end"] - self.log["page_start"] + 1
)
return super(Scrobble, self).save(*args, **kwargs) return super(Scrobble, self).save(*args, **kwargs)
def get_absolute_url(self): def get_absolute_url(self):
if not self.uuid: if not self.uuid:
self.uuid = uuid4() self.uuid = uuid4()
self.save() self.save(update_fields=["uuid"])
return reverse("scrobbles:detail", kwargs={"uuid": self.uuid}) return reverse("scrobbles:detail", kwargs={"uuid": self.uuid})
def push_to_archivebox(self): def push_to_archivebox(self):