From: Christian Heller Date: Tue, 3 Dec 2024 06:01:52 +0000 (+0100) Subject: For VideoFiles, renew .last_update any time .save() saves actual changes to other... X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/template?a=commitdiff_plain;h=e5a7520b9bc38fc51906cb3c3ea8113de8193f72;p=ytplom For VideoFiles, renew .last_update any time .save() saves actual changes to other DB-recored fields. --- diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 4b36b5a..d0b55e8 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -12,6 +12,7 @@ from uuid import uuid4 from pathlib import Path from threading import Thread from queue import Queue +from sqlite3 import Cursor # non-included libs import googleapiclient.discovery # type: ignore from mpv import MPV # type: ignore @@ -270,9 +271,22 @@ class VideoFile(DbData): self._renew_last_update() else: self.last_update = last_update + self._hash_on_last_update = hash(self) + + def __hash__(self) -> int: + return hash(f'{self.digest.b64}|{self.rel_path}|{self.flags}|' + f'{self.yt_id}|{self.last_update}|{self.tags_str}') def _renew_last_update(self): + print("DEBUG calling_renew_last_update", self.rel_path) self.last_update = DatetimeStr(datetime.now().strftime(TIMESTAMP_FMT)) + self._hash_on_last_update = hash(self) + + def save(self, conn: BaseDbConn) -> Cursor: + """Extend super().save by new .last_update if sufficient changes.""" + if hash(self) != self._hash_on_last_update: + self._renew_last_update() + return super().save(conn) @classmethod def get_by_yt_id(cls, conn: BaseDbConn, yt_id: YoutubeId) -> Self: @@ -324,7 +338,6 @@ class VideoFile(DbData): self.flags = FlagsInt(0) for flag in flags: self.flags = FlagsInt(self.flags | flag) - self._renew_last_update() def is_flag_set(self, flag_name: FlagName) -> bool: """Return if flag of flag_name is set in flags field."""