mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
fix: slow folder track count
+ etc
This commit is contained in:
+1
-1
@@ -64,7 +64,7 @@ def create_api():
|
||||
|
||||
app = OpenAPI(__name__, info=api_info, doc_prefix="/docs")
|
||||
# JWT CONFIGS
|
||||
app.config["JWT_SECRET_KEY"] = UserConfig().userId
|
||||
app.config["JWT_SECRET_KEY"] = UserConfig().serverId
|
||||
app.config["JWT_TOKEN_LOCATION"] = ["cookies", "headers"]
|
||||
app.config["JWT_COOKIE_CSRF_PROTECT"] = False
|
||||
app.config["JWT_SESSION_COOKIE"] = False
|
||||
|
||||
+3
-5
@@ -10,12 +10,13 @@ from pydantic import BaseModel, Field
|
||||
from flask_openapi3 import Tag
|
||||
from flask_openapi3 import APIBlueprint
|
||||
from showinfm import show_in_file_manager
|
||||
from memory_profiler import profile
|
||||
|
||||
from app import settings
|
||||
from app.db import TrackTable
|
||||
from app.db.sqlite.settings import SettingsSQLMethods as db
|
||||
from app.lib.folderslib import GetFilesAndDirs, get_folders
|
||||
from app.serializers.track import serialize_track
|
||||
from app.store.tracks import TrackStore as store
|
||||
from app.utils.wintools import is_windows, win_replace_slash
|
||||
|
||||
tag = Tag(name="Folders", description="Get folders and tracks in a directory")
|
||||
@@ -66,9 +67,7 @@ def get_folder_tree(body: FolderTree):
|
||||
else:
|
||||
req_dir = "/" + req_dir if not req_dir.startswith("/") else req_dir
|
||||
|
||||
print('stuff!')
|
||||
res = GetFilesAndDirs(req_dir, tracks_only=tracks_only)()
|
||||
print(res['folders'])
|
||||
res["folders"] = sorted(res["folders"], key=lambda i: i.name)
|
||||
|
||||
return res
|
||||
@@ -183,8 +182,7 @@ def get_tracks_in_path(query: GetTracksInPathQuery):
|
||||
|
||||
Used when adding tracks to the queue.
|
||||
"""
|
||||
tracks = store.get_tracks_in_path(query.path)
|
||||
tracks = sorted(tracks, key=lambda i: i.last_mod)
|
||||
tracks = TrackTable.get_tracks_in_path(query.path)
|
||||
tracks = (serialize_track(t) for t in tracks if Path(t.filepath).exists())
|
||||
|
||||
return {
|
||||
|
||||
@@ -61,11 +61,11 @@ def get_all_items(path: GetAllItemsPath, query: GetAllItemsQuery):
|
||||
is_artists = path.itemtype == "artists"
|
||||
|
||||
if is_albums:
|
||||
items = AlbumTable.get_all(query.start, query.limit)
|
||||
items, total = AlbumTable.get_all(query.start, query.limit)
|
||||
elif is_artists:
|
||||
items = ArtistTable.get_all(query.start, query.limit)
|
||||
items, total = ArtistTable.get_all(query.start, query.limit)
|
||||
|
||||
print(items)
|
||||
# print(items)
|
||||
|
||||
start = query.start
|
||||
limit = query.limit
|
||||
@@ -93,6 +93,7 @@ def get_all_items(path: GetAllItemsPath, query: GetAllItemsQuery):
|
||||
|
||||
for item in items:
|
||||
item_dict = serialize_album(item) if is_albums else serialize_artist(item)
|
||||
print(item_dict)
|
||||
|
||||
if sort_is_date:
|
||||
item_dict["help_text"] = item.date
|
||||
@@ -117,9 +118,9 @@ def get_all_items(path: GetAllItemsPath, query: GetAllItemsQuery):
|
||||
|
||||
if sort_is_artist_albumcount:
|
||||
item_dict["help_text"] = (
|
||||
f"{format_number(item['albumcount'])} album{'' if item['albumcount'] == 1 else 's'}"
|
||||
f"{format_number(item.albumcount)} album{'' if item.albumcount == 1 else 's'}"
|
||||
)
|
||||
|
||||
album_list.append(item_dict)
|
||||
|
||||
return {"items": album_list, "total": len(sorted_items)}
|
||||
return {"items": album_list, "total": total}
|
||||
|
||||
Reference in New Issue
Block a user