From d9688455fb2f99fdb2fc28373c3900f7f4cd69a9 Mon Sep 17 00:00:00 2001 From: mungai-njoroge Date: Sun, 30 Jul 2023 15:06:56 +0300 Subject: [PATCH] default migrations value to -1 + tiny fixes --- app/db/sqlite/queries.py | 2 +- app/lib/populate.py | 28 +++++++++++----------------- app/lib/taglib.py | 2 +- app/migrations/__init__.py | 5 +++++ app/models/track.py | 3 ++- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/db/sqlite/queries.py b/app/db/sqlite/queries.py index 7b007ac..f96f03a 100644 --- a/app/db/sqlite/queries.py +++ b/app/db/sqlite/queries.py @@ -91,6 +91,6 @@ CREATE TABLE IF NOT EXISTS dbmigrations ( ); INSERT INTO dbmigrations (version) -SELECT 0 +SELECT -1 WHERE NOT EXISTS (SELECT 1 FROM dbmigrations); """ diff --git a/app/lib/populate.py b/app/lib/populate.py index fcfd0d5..b845a8d 100644 --- a/app/lib/populate.py +++ b/app/lib/populate.py @@ -1,4 +1,3 @@ -import json import os from collections import deque from typing import Generator @@ -9,7 +8,8 @@ from tqdm import tqdm from app import settings from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb -from app.db.sqlite.lastfm.similar_artists import SQLiteLastFMSimilarArtists as lastfmdb +from app.db.sqlite.lastfm.similar_artists import \ + SQLiteLastFMSimilarArtists as lastfmdb from app.db.sqlite.settings import SettingsSQLMethods as sdb from app.db.sqlite.tracks import SQLiteTrackMethods from app.lib.albumslib import validate_albums @@ -124,7 +124,7 @@ class Populate: for track in tracks: try: - if track.last_mod == os.path.getmtime(track.filepath): + if track.last_mod == round(os.path.getmtime(track.filepath)): unmodified_paths.add(track.filepath) continue except (FileNotFoundError, OSError) as e: @@ -271,19 +271,13 @@ class FetchSimilarArtistsLastFM: def __init__(self) -> None: artists = ArtistStore.artists - try: - with Pool(processes=cpu_count()) as pool: - results = list( - tqdm( - pool.imap_unordered(save_similar_artists, artists), - total=len(artists), - desc="Fetching similar artists", - ) + with Pool(processes=cpu_count()) as pool: + results = list( + tqdm( + pool.imap_unordered(save_similar_artists, artists), + total=len(artists), + desc="Fetching similar artists", ) + ) - list(results) - except TypeError: - print("TypeError: Handled!!") - # 🤷 - # TypeError: JSONDecodeError.__init__() missing 2 required positional arguments: 'doc' and 'pos' - pass \ No newline at end of file + list(results) diff --git a/app/lib/taglib.py b/app/lib/taglib.py index 57a24d6..7e0e902 100644 --- a/app/lib/taglib.py +++ b/app/lib/taglib.py @@ -88,7 +88,7 @@ def get_tags(filepath: str): filename = (filepath.split("/")[-1]).replace(f".{filetype}", "") try: - last_mod = os.path.getmtime(filepath) + last_mod = round(os.path.getmtime(filepath)) except FileNotFoundError: return None diff --git a/app/migrations/__init__.py b/app/migrations/__init__.py index 08faa26..e91b00e 100644 --- a/app/migrations/__init__.py +++ b/app/migrations/__init__.py @@ -34,6 +34,11 @@ def apply_migrations(): version = MigrationManager.get_version() + # is clean install + if version == -1: + MigrationManager.set_version(len(migrations)) + return + if version != len(migrations): # run migrations after the previous migration version for migration in migrations[(version - 1) :]: diff --git a/app/models/track.py b/app/models/track.py index 43a96dd..59f27d8 100644 --- a/app/models/track.py +++ b/app/models/track.py @@ -33,7 +33,7 @@ class Track: title: str track: int trackhash: str - last_mod: float + last_mod: str | int filetype: str = "" image: str = "" @@ -46,6 +46,7 @@ class Track: def __post_init__(self): self.og_title = self.title self.og_album = self.album + self.last_mod = int(self.last_mod) if self.artist is not None: artists = split_artists(self.artist)