From 3cd0527962da296018e926c6cb165bbe648cfa76 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Tue, 21 Jun 2022 16:24:27 +0300 Subject: [PATCH] use count_documents to get folder count - map filenames with db data --- server/app/db/mongodb/tracks.py | 12 +++++++++--- server/app/functions.py | 14 ++++++-------- server/app/lib/folderslib.py | 17 +++++++++++++---- server/app/lib/populate.py | 1 - server/app/prep.py | 1 - src/components/LeftSidebar/nowPlaying.vue | 1 + src/components/shared/ArtistCard.vue | 1 + src/components/shared/SongItem.vue | 14 +++++--------- src/components/shared/TrackItem.vue | 6 ++++++ 9 files changed, 41 insertions(+), 26 deletions(-) diff --git a/server/app/db/mongodb/tracks.py b/server/app/db/mongodb/tracks.py index 9bd3d0d1..a7c3b1be 100644 --- a/server/app/db/mongodb/tracks.py +++ b/server/app/db/mongodb/tracks.py @@ -83,6 +83,13 @@ class Tracks(MongoTracks): songs = self.collection.find({"folder": query}).sort("title", pymongo.ASCENDING) return convert_many(songs) + def find_songs_by_filenames(self, filenames: list) -> list: + """ + Returns a list of all the tracks matching the filenames in the query params. + """ + songs = self.collection.find({"filepath": {"$in": filenames}}) + return convert_many(songs) + def find_songs_by_folder_og(self, query: str) -> list: """ Returns an unsorted list of all the track matching the folder in the query params @@ -90,14 +97,13 @@ class Tracks(MongoTracks): songs = self.collection.find({"folder": query}) return convert_many(songs) - def find_tracks_inside_path_regex(self, path: str) -> list: + def find_tracks_inside_path_regex(self, path: str) -> int: """ Returns a list of all the tracks matching the path in the query params. """ - songs = self.collection.find( + return self.collection.count_documents( {"filepath": {"$regex": f"^{path}", "$options": "i"}} ) - return convert_many(songs) def find_songs_by_artist(self, query: str) -> list: """ diff --git a/server/app/functions.py b/server/app/functions.py index 561760be..e8520266 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -22,16 +22,14 @@ def reindex_tracks(): Checks for new songs every 5 minutes. """ - while True: - trackslib.validate_tracks() + # while True: + trackslib.validate_tracks() - Populate() - CreateAlbums() + Populate() + CreateAlbums() - if helpers.Ping()(): - CheckArtistImages()() - - time.sleep(60) + if helpers.Ping()(): + CheckArtistImages()() @helpers.background diff --git a/server/app/lib/folderslib.py b/server/app/lib/folderslib.py index b5872736..c3f866b0 100644 --- a/server/app/lib/folderslib.py +++ b/server/app/lib/folderslib.py @@ -1,11 +1,14 @@ from dataclasses import dataclass from os import scandir +import time from typing import Tuple +from concurrent.futures import ThreadPoolExecutor from app.models import Folder from app.models import Track from app import instances +from app.logger import Log @dataclass @@ -28,7 +31,7 @@ def create_folder(dir: Dir) -> Folder: "name": dir.path.split("/")[-1], "path": dir.path, "is_sym": dir.is_sym, - "trackcount": get_folder_track_count(dir.path), + "trackcount": instances.tracks_instance.find_tracks_inside_path_regex(dir.path), } return Folder(folder) @@ -59,11 +62,17 @@ class getFnF: dirs.append(Dir(**dir)) elif entry.is_file() and entry.name.endswith((".mp3", ".flac")): files.append(entry.path) - tracks = instances.tracks_instance.find_songs_by_folder(self.path) + + tracks = instances.tracks_instance.find_songs_by_filenames(files) tracks = [Track(track) for track in tracks] + s = time.time() - folders = [create_folder(dir) for dir in dirs] - + # folders = [create_folder(dir) for dir in dirs] + with ThreadPoolExecutor() as pool: + iter = pool.map(create_folder, dirs) + folders = [i for i in iter if i is not None] + d = time.time() - s + Log(f"Did that in {d} seconds") folders = filter(lambda f: f.trackcount > 0, folders) return tracks, folders diff --git a/server/app/lib/populate.py b/server/app/lib/populate.py index 6fa2aead..7509585b 100644 --- a/server/app/lib/populate.py +++ b/server/app/lib/populate.py @@ -1,5 +1,4 @@ from dataclasses import dataclass -from pprint import pprint import time from concurrent.futures import ThreadPoolExecutor from typing import List diff --git a/server/app/prep.py b/server/app/prep.py index 0335c371..bb80b71b 100644 --- a/server/app/prep.py +++ b/server/app/prep.py @@ -21,7 +21,6 @@ class CopyFiles: for entry in files: src = os.path.join(os.getcwd(), entry["src"]) - print(f"Copying {src} to {entry['dest']}") if entry["is_dir"]: shutil.copytree( diff --git a/src/components/LeftSidebar/nowPlaying.vue b/src/components/LeftSidebar/nowPlaying.vue index 995399fc..0b7c8e00 100644 --- a/src/components/LeftSidebar/nowPlaying.vue +++ b/src/components/LeftSidebar/nowPlaying.vue @@ -102,6 +102,7 @@ const queue = useQStore(); .title { font-weight: 900; + word-break: break-all; } .artists { diff --git a/src/components/shared/ArtistCard.vue b/src/components/shared/ArtistCard.vue index d5d2a608..5f2acfc8 100644 --- a/src/components/shared/ArtistCard.vue +++ b/src/components/shared/ArtistCard.vue @@ -63,6 +63,7 @@ defineProps<{ font-size: 0.9rem; font-weight: 510; max-width: 7rem; + text-transform: capitalize; } } diff --git a/src/components/shared/SongItem.vue b/src/components/shared/SongItem.vue index 4cf7391d..aeda9c2f 100644 --- a/src/components/shared/SongItem.vue +++ b/src/components/shared/SongItem.vue @@ -117,15 +117,6 @@ function emitUpdate(track: Track) { user-select: none; -moz-user-select: none; - .context { - position: fixed; - top: 0; - left: 0; - height: 45px; - width: 45px; - background-color: red; - } - @include tablet-landscape { grid-template-columns: 1.5rem 1.5fr 1fr 1.5fr; } @@ -145,6 +136,8 @@ function emitUpdate(track: Track) { } .song-album { + word-break: break-all; + .album { cursor: pointer; max-width: max-content; @@ -156,6 +149,8 @@ function emitUpdate(track: Track) { } .song-artists { + word-break: break-all; + .artist { cursor: pointer; } @@ -199,6 +194,7 @@ function emitUpdate(track: Track) { .title { cursor: pointer; + word-break: break-all; } } diff --git a/src/components/shared/TrackItem.vue b/src/components/shared/TrackItem.vue index a03a6a03..7086f3a5 100644 --- a/src/components/shared/TrackItem.vue +++ b/src/components/shared/TrackItem.vue @@ -122,7 +122,13 @@ const playThis = (track: Track) => { margin: 0 0.5rem 0 0; background-image: url(../../assets/images/null.webp); } + + .title { + word-break: break-all; + } + .artist { + word-break: break-all; font-size: small; color: rgba(255, 255, 255, 0.637); }