Skip to content

Commit

Permalink
minor improvements to handling source drifts during mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 28, 2023
1 parent f392184 commit 14502b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion rose/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ def _update_cache_for_releases_executor(
# Handle cover art change.
try:
cover = next(
Path(f).resolve() for f in files if os.path.basename(f).lower() in c.valid_art_exts
Path(f).resolve()
for f in files
if os.path.basename(f).lower() in c.valid_cover_arts
)
except StopIteration: # No cover art in directory.
cover = None
Expand Down
12 changes: 7 additions & 5 deletions rose/collages.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ def remove_release_from_collage(
with lock(c, collage_lock_name(collage_name)):
with path.open("rb") as fp:
data = tomllib.load(fp)
data["releases"] = data.get("releases", [])
data["releases"] = [r for r in data.get("releases", []) if r["uuid"] != release_id]
old_releases = data.get("releases", [])
new_releases = [r for r in old_releases if r["uuid"] != release_id]
if old_releases == new_releases:
logger.info(f"No-Op: Release {release_dirname} not in collage {collage_name}")
return
data["releases"] = new_releases
with path.open("wb") as fp:
tomli_w.dump(data, fp)
logger.info(f"Removed release {release_dirname} from collage {collage_name}")
Expand All @@ -120,9 +124,7 @@ def add_release_to_collage(
# duplicate collage entries.
for r in data["releases"]:
if r["uuid"] == release_id:
logger.debug(
f"No-Opping: Release {release_dirname} already in collage {collage_name}"
)
logger.info(f"No-Op: Release {release_dirname} already in collage {collage_name}")
return
data["releases"].append({"uuid": release_id, "description_meta": release_dirname})
with path.open("wb") as fp:
Expand Down
12 changes: 7 additions & 5 deletions rose/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ def remove_track_from_playlist(
with lock(c, playlist_lock_name(playlist_name)):
with path.open("rb") as fp:
data = tomllib.load(fp)
data["tracks"] = data.get("tracks", [])
data["tracks"] = [r for r in data.get("tracks", []) if r["uuid"] != track_id]
old_tracks = data.get("tracks", [])
new_tracks = [r for r in old_tracks if r["uuid"] != track_id]
if old_tracks == new_tracks:
logger.info(f"No-Op: track {track_filename} not in playlist {playlist_name}")
return
data["tracks"] = new_tracks
with path.open("wb") as fp:
tomli_w.dump(data, fp)
logger.info(f"Removed track {track_filename} from playlist {playlist_name}")
Expand All @@ -121,9 +125,7 @@ def add_track_to_playlist(
# duplicate playlist entries.
for r in data["tracks"]:
if r["uuid"] == track_id:
logger.debug(
f"No-Opping: Track {track_filename} already in playlist {playlist_name}"
)
logger.info(f"No-Op: Track {track_filename} already in playlist {playlist_name}")
return
data["tracks"].append({"uuid": track_id, "description_meta": track_filename})
with path.open("wb") as fp:
Expand Down
6 changes: 6 additions & 0 deletions rose/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ def from_toml(cls, toml: str) -> MetadataRelease:

def edit_release(c: Config, release_id_or_virtual_dirname: str) -> None:
release_id, _ = resolve_release_ids(c, release_id_or_virtual_dirname)

# Trigger a quick cache update to ensure we are reading the liveliest data.
source_path = get_release_source_path_from_id(c, release_id)
assert source_path is not None
update_cache_for_releases(c, [source_path])

with lock(c, release_lock_name(release_id)):
cachedata = get_release(c, release_id_or_virtual_dirname)
if not cachedata:
Expand Down

0 comments on commit 14502b7

Please sign in to comment.