mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
fix: recently added items sort order in the homepage
.ie. stop relying on folder last mod date, and use the latest file from the folder + bump watchdog to v4 + add WIP docs (stashed in .github/code.docs for now)
This commit is contained in:
@@ -165,12 +165,28 @@ def check_folder_type(group_: group_type) -> str:
|
||||
|
||||
|
||||
def group_track_by_folders(tracks: Track):
|
||||
"""
|
||||
Groups tracks by folder and returns a list of groups sorted by last modified date.
|
||||
|
||||
Uses generator expressions to avoid creating intermediate lists.
|
||||
"""
|
||||
|
||||
# INFO: sort tracks by folder name, then group by folder name
|
||||
tracks = sorted(tracks, key=lambda t: t.folder)
|
||||
groups = groupby(tracks, lambda t: t.folder)
|
||||
|
||||
# INFO: sort tracks by last modified date in descending order to get the most recent last modified date
|
||||
groups = (
|
||||
{"folder": folder, "tracks": list(tracks), "time": os.path.getctime(folder)}
|
||||
(folder, sorted(tracks, key=lambda t: t.last_mod, reverse=True))
|
||||
for folder, tracks in groups
|
||||
)
|
||||
|
||||
# INFO: Return a generator of the groups
|
||||
groups = (
|
||||
{"folder": folder, "tracks": list(tracks), "time": tracks[0].last_mod}
|
||||
for folder, tracks in groups
|
||||
)
|
||||
|
||||
# sort groups by last modified date
|
||||
return sorted(groups, key=lambda group: group["time"], reverse=True)
|
||||
|
||||
|
||||
+4
-3
@@ -4,6 +4,7 @@ import random
|
||||
|
||||
from app.db.sqlite.albumcolors import SQLiteAlbumMethods as aldb
|
||||
from app.models import Album, Track
|
||||
from app.utils.customlist import CustomList
|
||||
from app.utils.remove_duplicates import remove_duplicates
|
||||
|
||||
from ..utils.hashing import create_hash
|
||||
@@ -14,7 +15,7 @@ ALBUM_LOAD_KEY = ""
|
||||
|
||||
|
||||
class AlbumStore:
|
||||
albums: list[Album] = []
|
||||
albums: list[Album] = CustomList()
|
||||
|
||||
@staticmethod
|
||||
def create_album(track: Track):
|
||||
@@ -35,7 +36,7 @@ class AlbumStore:
|
||||
global ALBUM_LOAD_KEY
|
||||
ALBUM_LOAD_KEY = instance_key
|
||||
|
||||
cls.albums = []
|
||||
cls.albums = CustomList()
|
||||
|
||||
print("Loading albums... ", end="")
|
||||
tracks = remove_duplicates(TrackStore.tracks)
|
||||
@@ -172,4 +173,4 @@ class AlbumStore:
|
||||
"""
|
||||
Removes an album from the store.
|
||||
"""
|
||||
cls.albums = [a for a in cls.albums if a.albumhash != albumhash]
|
||||
cls.albums = CustomList(a for a in cls.albums if a.albumhash != albumhash)
|
||||
|
||||
@@ -4,6 +4,7 @@ from app.db.sqlite.artistcolors import SQLiteArtistMethods as ardb
|
||||
from app.lib.artistlib import get_all_artists
|
||||
from app.models import Artist
|
||||
from app.utils.bisection import UseBisection
|
||||
from app.utils.customlist import CustomList
|
||||
from app.utils.progressbar import tqdm
|
||||
|
||||
from .albums import AlbumStore
|
||||
@@ -13,7 +14,7 @@ ARTIST_LOAD_KEY = ""
|
||||
|
||||
|
||||
class ArtistStore:
|
||||
artists: list[Artist] = []
|
||||
artists: list[Artist] = CustomList()
|
||||
|
||||
@classmethod
|
||||
def load_artists(cls, instance_key: str):
|
||||
@@ -24,7 +25,9 @@ class ArtistStore:
|
||||
ARTIST_LOAD_KEY = instance_key
|
||||
|
||||
print("Loading artists... ", end="")
|
||||
cls.artists = get_all_artists(TrackStore.tracks, AlbumStore.albums)
|
||||
cls.artists.extend(
|
||||
get_all_artists(TrackStore.tracks, AlbumStore.albums)
|
||||
)
|
||||
print("Done!")
|
||||
for artist in ardb.get_all_artists():
|
||||
if instance_key != ARTIST_LOAD_KEY:
|
||||
@@ -110,4 +113,4 @@ class ArtistStore:
|
||||
"""
|
||||
Removes an artist from the store.
|
||||
"""
|
||||
cls.artists = [a for a in cls.artists if a.artisthash != artisthash]
|
||||
cls.artists = CustomList(a for a in cls.artists if a.artisthash != artisthash)
|
||||
|
||||
+5
-3
@@ -4,14 +4,14 @@ from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||
from app.db.sqlite.tracks import SQLiteTrackMethods as tdb
|
||||
from app.models import Track
|
||||
from app.utils.bisection import UseBisection
|
||||
from app.utils.customlist import CustomList
|
||||
from app.utils.remove_duplicates import remove_duplicates
|
||||
from app.utils.progressbar import tqdm
|
||||
|
||||
TRACKS_LOAD_KEY = ""
|
||||
|
||||
|
||||
class TrackStore:
|
||||
tracks: list[Track] = []
|
||||
tracks: list[Track] = CustomList()
|
||||
|
||||
@classmethod
|
||||
def load_all_tracks(cls, instance_key: str):
|
||||
@@ -23,7 +23,7 @@ class TrackStore:
|
||||
global TRACKS_LOAD_KEY
|
||||
TRACKS_LOAD_KEY = instance_key
|
||||
|
||||
cls.tracks = list(tdb.get_all_tracks())
|
||||
cls.tracks = CustomList(tdb.get_all_tracks())
|
||||
|
||||
fav_hashes = favdb.get_fav_tracks()
|
||||
fav_hashes = " ".join([t[1] for t in fav_hashes])
|
||||
@@ -44,6 +44,7 @@ class TrackStore:
|
||||
"""
|
||||
|
||||
cls.tracks.append(track)
|
||||
print(f"\n A: Current track count:, {len(cls.tracks)} \n")
|
||||
|
||||
@classmethod
|
||||
def add_tracks(cls, tracks: list[Track]):
|
||||
@@ -52,6 +53,7 @@ class TrackStore:
|
||||
"""
|
||||
|
||||
cls.tracks.extend(tracks)
|
||||
print(f"\n E: Current track count:, {len(cls.tracks)} \n")
|
||||
|
||||
@classmethod
|
||||
def remove_track_obj(cls, track: Track):
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
class CustomList(list):
|
||||
# TODO: I think SharedMemoryList implementation will be done here.
|
||||
# This list should be used as a normal list without any changes in the stores.
|
||||
|
||||
def __getitem__(self, index):
|
||||
# Do some shared memory stuff here
|
||||
return super().__getitem__(index)
|
||||
|
||||
def __iter__(self) -> Iterator:
|
||||
# Do some shared memory stuff here
|
||||
return super().__iter__()
|
||||
Reference in New Issue
Block a user