From: Christian Heller Date: Fri, 9 May 2025 15:11:01 +0000 (+0200) Subject: Release DownloadsManager._db_sync DB connections from waiting for file hash generation. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D?a=commitdiff_plain;h=HEAD;p=ytplom Release DownloadsManager._db_sync DB connections from waiting for file hash generation. --- diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index a3f337b..2eed335 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -826,28 +826,30 @@ class DownloadsManager: def _sync_db(self): with DbConn() as conn: VideoFile.purge_deleteds(conn) + conn.commit() known_paths = [file.rel_path for file in VideoFile.get_all(conn)] - old_cwd = Path.cwd() - chdir(PATH_DOWNLOADS) - for path in [p for p in Path('.').iterdir() if p.is_file()]: - yt_id = self._id_from_filename(path) - if path not in known_paths: - print(f'SYNC: new file {path}, saving to YT ID "{yt_id}".') - file = VideoFile(digest=None, - rel_path=path, - yt_id=yt_id, - tags_str=VideoFile.tags_default.joined) + old_cwd = Path.cwd() + chdir(PATH_DOWNLOADS) + for path in [p for p in Path('.').iterdir() if p.is_file()]: + yt_id = self._id_from_filename(path) + if path not in known_paths: + print(f'SYNC: new file {path}, saving to YT ID "{yt_id}".') + file = VideoFile(digest=None, + rel_path=path, + yt_id=yt_id, + tags_str=VideoFile.tags_default.joined) + with DbConn() as conn: file.save(conn) conn.commit() + with DbConn() as conn: + for path in [p for p in Path('.').iterdir() if p.is_file()]: + yt_id = self._id_from_filename(path) if (yt_id not in self._last_updates or 'present' != self._last_updates[yt_id]['status']): - self._update_status( - yt_id, - 'present', - str(path), - VideoFile.get_by_yt_id(conn, yt_id).digest.b64) + digest64 = VideoFile.get_by_yt_id(conn, yt_id).digest.b64 + self._update_status(yt_id, 'present', str(path), digest64) self._files = VideoFile.get_all(conn) - chdir(old_cwd) + chdir(old_cwd) def last_update_for(self, conn: DbConn,