fix: recently added

This commit is contained in:
cwilvx
2024-06-30 21:40:49 +03:00
parent b9ad07441a
commit 5759521de0
4 changed files with 113 additions and 58 deletions
+17 -4
View File
@@ -30,14 +30,14 @@ def create_all():
class Base(MasterBase, DeclarativeBase):
@classmethod
def get_all_hashes(cls):
def get_all_hashes(cls, create_date: int | None = None):
with DbManager() as conn:
if cls.__tablename__ == "track":
stmt = select(TrackTable.trackhash)
stmt = select(TrackTable.trackhash).where(cls.last_mod < create_date)
elif cls.__tablename__ == "album":
stmt = select(AlbumTable.albumhash)
stmt = select(AlbumTable.albumhash).where(cls.created_date < create_date)
elif cls.__tablename__ == "artist":
stmt = select(ArtistTable.artisthash)
stmt = select(ArtistTable.artisthash).where(cls.created_date < create_date)
result = conn.execute(stmt)
return {row[0] for row in result.fetchall()}
@@ -194,6 +194,18 @@ class TrackTable(Base):
)
return tracks_to_dataclasses(result.fetchall())
@classmethod
def get_recently_added(cls, start: int, limit: int):
with DbManager() as conn:
result = conn.execute(
select(TrackTable)
.order_by(TrackTable.last_mod.desc())
.offset(start)
.limit(limit)
)
return tracks_to_dataclasses(result.fetchall())
@classmethod
def remove_tracks_by_filepaths(cls, filepaths: set[str]):
with DbManager(commit=True) as conn:
@@ -238,6 +250,7 @@ class AlbumTable(Base):
all = result.fetchall()
return albums_to_dataclasses(all)
@classmethod
def get_album_by_albumhash(cls, hash: str):
with DbManager() as conn: