fix: slow folder track count

+ etc
This commit is contained in:
cwilvx
2024-06-27 00:02:08 +03:00
parent 54a1b85d8b
commit 1a66194c6c
13 changed files with 183 additions and 95 deletions
+2 -40
View File
@@ -2,12 +2,11 @@ import os
from pathlib import Path
from app.logger import log
from app.models import Folder, Track
from app.models import Folder
from app.serializers.track import serialize_tracks
from app.settings import SUPPORTED_FILES
from app.utils.wintools import win_replace_slash
from app.store.tracks import TrackStore
from app.db import TrackTable as TrackDB
@@ -51,39 +50,6 @@ def get_folders(paths: list[str]):
for f in folders
if f["trackcount"] > 0
]
# count_dict = {
# "tracks": {path: 0 for path in paths},
# # folders are immediate children of the root folder
# "folders": {path: set() for path in paths},
# }
# for track in TrackStore.tracks:
# for path in paths:
# # a child path should be longer than the root path
# if len(track.folder) >= len(path) and track.folder.startswith(path):
# count_dict["tracks"][path] += 1
# # counting subfolders
# p = get_first_child_from_path(path, track.folder)
# if p:
# count_dict["folders"][path].add(p)
# folders = [
# {
# "path": path,
# "trackcount": count_dict["tracks"][path],
# "foldercount": len(count_dict["folders"][path]),
# }
# for path in paths
# ]
# return [
# create_folder(f["path"], f["trackcount"], f["foldercount"])
# for f in folders
# if f["trackcount"] > 0
# ]
class GetFilesAndDirs:
@@ -143,10 +109,6 @@ class GetFilesAndDirs:
tracks = []
if files:
tracks = TrackDB.get_tracks_by_filepaths(files)
print("printing files")
print(tracks)
# tracks = TrackStore.get_tracks_by_filepaths(files)
folders = []
if not self.tracks_only:
@@ -160,7 +122,7 @@ class GetFilesAndDirs:
return {
"path": path,
"tracks": tracks,
"tracks": serialize_tracks(tracks),
"folders": folders,
}
+12 -7
View File
@@ -45,6 +45,8 @@ class Populate:
"""
def __init__(self, instance_key: str) -> None:
return
global POPULATE_KEY
POPULATE_KEY = instance_key
@@ -152,15 +154,18 @@ class Populate:
@staticmethod
def tag_untagged(untagged: set[str], key: str):
for file in tqdm(untagged, desc="Reading files"):
if POPULATE_KEY != key:
log.warning("'Populate.tag_untagged': Populate key changed")
return
pass
# for file in tqdm(untagged, desc="Reading files"):
# if POPULATE_KEY != key:
# log.warning("'Populate.tag_untagged': Populate key changed")
# return
tags = get_tags(file)
# tags = get_tags(file)
if tags is not None:
TrackTable.insert_one(tags)
# if tags is not None:
# TrackTable.insert_one(tags)
# =============================================
# log.info("Found %s new tracks", len(untagged))
# # tagged_tracks: deque[dict] = deque()
+6 -3
View File
@@ -30,6 +30,7 @@ class IndexTracks:
if tags is not None:
TrackTable.insert_one(tags)
del tags
class IndexAlbums:
def __init__(self) -> None:
@@ -84,6 +85,7 @@ class IndexAlbums:
pprint(albums)
AlbumTable.insert_many(list(albums.values()))
del albums
class IndexArtists:
@@ -146,10 +148,11 @@ class IndexArtists:
pprint(artists)
ArtistTable.insert_many(list(artists.values()))
del artists
class IndexEverything:
def __init__(self) -> None:
# IndexTracks()
# IndexAlbums()
# IndexArtists()
IndexTracks()
IndexAlbums()
IndexArtists()
pass