fix is_favorite setter on populate

This commit is contained in:
cwilvx
2024-05-26 14:17:12 +03:00
parent eb70887c93
commit c8325101d5
3 changed files with 16 additions and 21 deletions
+11 -4
View File
@@ -137,7 +137,7 @@ class Populate:
unmodified_paths.add(track.filepath) unmodified_paths.add(track.filepath)
continue continue
except (FileNotFoundError, OSError) as e: except (FileNotFoundError, OSError) as e:
log.warning(e) # REVIEW More informations = good log.warning(e) # REVIEW More informations = good
TrackStore.remove_track_obj(track) TrackStore.remove_track_obj(track)
remove_tracks_by_filepaths(track.filepath) remove_tracks_by_filepaths(track.filepath)
@@ -155,8 +155,14 @@ class Populate:
tagged_tracks: deque[dict] = deque() tagged_tracks: deque[dict] = deque()
tagged_count = 0 tagged_count = 0
fav_tracks = favdb.get_fav_tracks() favs = favdb.get_fav_tracks()
fav_tracks = set(t[1] for t in fav_tracks)
records = dict()
for fav in favs:
r = records.setdefault(fav[1], set())
r.add(fav[4])
for file in tqdm(untagged, desc="Reading files"): for file in tqdm(untagged, desc="Reading files"):
if POPULATE_KEY != key: if POPULATE_KEY != key:
@@ -168,7 +174,8 @@ class Populate:
if tags is not None: if tags is not None:
tagged_tracks.append(tags) tagged_tracks.append(tags)
track = Track(**tags) track = Track(**tags)
track.is_favorite = track.trackhash in fav_tracks
track.fav_userids = list(records.get(track.trackhash, set()))
TrackStore.add_track(track) TrackStore.add_track(track)
+4 -16
View File
@@ -31,27 +31,15 @@ class TrackStore:
records = dict() records = dict()
for fav in favs: for fav in favs:
if fav[1] not in records: r = records.setdefault(fav[1], set())
# if trackhash not in dict, add it r.add(fav[4])
# and set the value to a set containing the userid
records[fav[1]] = {fav[4]}
# if trackhash is in dict, add the userid to the set
records[fav[1]].add(fav[4])
for track in cls.tracks: for track in cls.tracks:
if instance_key != TRACKS_LOAD_KEY: if instance_key != TRACKS_LOAD_KEY:
return return
try: userids = records.get(track.trackhash, set())
track.fav_userids = list(records[track.trackhash]) track.fav_userids = list(userids)
except KeyError:
track.fav_userids = []
# if track.trackhash in fav_hashes:
# fav = [t for t in favs if t["hash"] == track.trackhash][0]
# print(fav)
# track.favorite_data = [i["userid"] for i in fav]
print("Done!") print("Done!")
+1 -1
View File
@@ -5,7 +5,7 @@ description = ""
authors = ["geoffrey45 <geoffreymungai45@gmail.com>"] authors = ["geoffrey45 <geoffreymungai45@gmail.com>"]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = ">=3.11,<3.12" python = ">=3.10,<3.12"
Flask = "^2.0.2" Flask = "^2.0.2"
Flask-Cors = "^3.0.10" Flask-Cors = "^3.0.10"
requests = "^2.27.1" requests = "^2.27.1"