Implemented clearing cache
This commit is contained in:
@@ -783,6 +783,10 @@ class CachingAdapter(Adapter):
|
||||
SONG_FILE = "song_file"
|
||||
SONG_FILE_PERMANENT = "song_file_permanent"
|
||||
|
||||
# These are only for clearing the cache, and will only do deletion
|
||||
ALL_SONGS = "all_songs"
|
||||
EVERYTHING = "everything"
|
||||
|
||||
@abc.abstractmethod
|
||||
def ingest_new_data(self, data_key: CachedDataKey, param: Optional[str], data: Any):
|
||||
"""
|
||||
|
@@ -857,4 +857,24 @@ class FilesystemAdapter(CachingAdapter):
|
||||
if cache_info:
|
||||
self._compute_song_filename(cache_info).unlink(missing_ok=True)
|
||||
|
||||
cache_info.delete_instance()
|
||||
elif data_key == CachingAdapter.CachedDataKey.ALL_SONGS:
|
||||
shutil.rmtree(str(self.music_dir))
|
||||
shutil.rmtree(str(self.cover_art_dir))
|
||||
self.music_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.cover_art_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
models.CacheInfo.update({"valid": False}).where(
|
||||
models.CacheInfo.cache_key == CachingAdapter.CachedDataKey.SONG_FILE
|
||||
).execute()
|
||||
models.CacheInfo.update({"valid": False}).where(
|
||||
models.CacheInfo.cache_key
|
||||
== CachingAdapter.CachedDataKey.COVER_ART_FILE
|
||||
).execute()
|
||||
|
||||
elif data_key == CachingAdapter.CachedDataKey.EVERYTHING:
|
||||
self._do_delete_data(CachingAdapter.CachedDataKey.ALL_SONGS, None)
|
||||
for table in models.ALL_TABLES:
|
||||
table.truncate_table()
|
||||
|
||||
if cache_info:
|
||||
cache_info.delete_instance()
|
||||
|
@@ -1224,3 +1224,21 @@ class AdapterManager:
|
||||
else cached_statuses[song_id]
|
||||
for song_id in song_ids
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def clear_song_cache():
|
||||
assert AdapterManager._instance
|
||||
if not AdapterManager._instance.caching_adapter:
|
||||
return
|
||||
AdapterManager._instance.caching_adapter.delete_data(
|
||||
CachingAdapter.CachedDataKey.ALL_SONGS, None
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def clear_entire_cache():
|
||||
assert AdapterManager._instance
|
||||
if not AdapterManager._instance.caching_adapter:
|
||||
return
|
||||
AdapterManager._instance.caching_adapter.delete_data(
|
||||
CachingAdapter.CachedDataKey.EVERYTHING, None
|
||||
)
|
||||
|
@@ -333,7 +333,6 @@ class ArtistDetailPanel(Gtk.Box):
|
||||
if self.artist_details_expanded:
|
||||
self.artist_artwork.get_style_context().remove_class("collapsed")
|
||||
self.artist_name.get_style_context().remove_class("collapsed")
|
||||
self.artist_artwork.set_image_size(300)
|
||||
self.artist_indicator.set_text("ARTIST")
|
||||
self.artist_stats.set_markup(self.format_stats(artist))
|
||||
|
||||
@@ -359,7 +358,6 @@ class ArtistDetailPanel(Gtk.Box):
|
||||
else:
|
||||
self.artist_artwork.get_style_context().add_class("collapsed")
|
||||
self.artist_name.get_style_context().add_class("collapsed")
|
||||
self.artist_artwork.set_image_size(70)
|
||||
self.artist_indicator.hide()
|
||||
self.artist_stats.hide()
|
||||
self.artist_bio.hide()
|
||||
@@ -391,6 +389,11 @@ class ArtistDetailPanel(Gtk.Box):
|
||||
self.artist_artwork.set_from_file(cover_art_filename)
|
||||
self.artist_artwork.set_loading(False)
|
||||
|
||||
if self.artist_details_expanded:
|
||||
self.artist_artwork.set_image_size(300)
|
||||
else:
|
||||
self.artist_artwork.set_image_size(70)
|
||||
|
||||
# Event Handlers
|
||||
# =========================================================================
|
||||
def on_view_refresh_click(self, *args):
|
||||
|
@@ -34,6 +34,7 @@ class EditServerDialog(EditFormDialog):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# TODO figure out how to do this
|
||||
# def on_test_server_clicked(self, event: Any):
|
||||
# # Instantiate the server.
|
||||
# server_address = self.data["server_address"].get_text()
|
||||
|
@@ -166,7 +166,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
if hasattr(active_panel, "update"):
|
||||
active_panel.update(app_config, force=force)
|
||||
|
||||
self.player_controls.update(app_config)
|
||||
self.player_controls.update(app_config, force=force)
|
||||
|
||||
def _create_stack(self, **kwargs: Gtk.Widget) -> Gtk.Stack:
|
||||
stack = Gtk.Stack()
|
||||
@@ -340,9 +340,8 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
|
||||
# Clear Song File Cache
|
||||
menu_items = [
|
||||
("Clear Song File Cache", lambda _: print("clear song file cache")),
|
||||
("Clear Metadata Cache", lambda _: print("clear metadata cache")),
|
||||
("Clear Entire Cache", lambda _: print("clear entire cache")),
|
||||
("Delete Cached Song Files", self._clear_song_file_cache),
|
||||
("Delete Cached Song Files and Metadata", self._clear_entire_cache),
|
||||
]
|
||||
for text, clicked_fn in menu_items:
|
||||
clear_song_cache = self._create_model_button(text, clicked_fn)
|
||||
@@ -584,6 +583,40 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
|
||||
return False
|
||||
|
||||
def _prompt_confirm_clear_cache(
|
||||
self, title: str, detail_text: str
|
||||
) -> Gtk.ResponseType:
|
||||
confirm_dialog = Gtk.MessageDialog(
|
||||
transient_for=self.get_toplevel(),
|
||||
message_type=Gtk.MessageType.WARNING,
|
||||
buttons=Gtk.ButtonsType.NONE,
|
||||
text=title,
|
||||
)
|
||||
confirm_dialog.add_buttons(
|
||||
Gtk.STOCK_DELETE,
|
||||
Gtk.ResponseType.YES,
|
||||
Gtk.STOCK_CANCEL,
|
||||
Gtk.ResponseType.CANCEL,
|
||||
)
|
||||
confirm_dialog.format_secondary_markup(detail_text)
|
||||
result = confirm_dialog.run()
|
||||
confirm_dialog.destroy()
|
||||
return result
|
||||
|
||||
def _clear_song_file_cache(self, _):
|
||||
title = "Confirm Delete Song Files"
|
||||
detail_text = "Are you sure you want to delete all cached song files? Your song metadata will be preserved." # noqa: 512
|
||||
if self._prompt_confirm_clear_cache(title, detail_text) == Gtk.ResponseType.YES:
|
||||
AdapterManager.clear_song_cache()
|
||||
self.emit("refresh-window", {}, True)
|
||||
|
||||
def _clear_entire_cache(self, _):
|
||||
title = "Confirm Delete Song Files and Metadata"
|
||||
detail_text = "Are you sure you want to delete all cached song files and corresponding metadata?" # noqa: 512
|
||||
if self._prompt_confirm_clear_cache(title, detail_text) == Gtk.ResponseType.YES:
|
||||
AdapterManager.clear_entire_cache()
|
||||
self.emit("refresh-window", {}, True)
|
||||
|
||||
def _on_downloads_menu_clicked(self, *args):
|
||||
self.downloads_popover.popup()
|
||||
self.downloads_popover.show_all()
|
||||
|
@@ -63,7 +63,7 @@ class PlayerControls(Gtk.ActionBar):
|
||||
self.set_center_widget(playback_controls)
|
||||
self.pack_end(play_queue_volume)
|
||||
|
||||
def update(self, app_config: AppConfiguration):
|
||||
def update(self, app_config: AppConfiguration, force: bool = False):
|
||||
self.current_device = app_config.state.current_device
|
||||
|
||||
duration = (
|
||||
@@ -176,7 +176,7 @@ class PlayerControls(Gtk.ActionBar):
|
||||
self.update_device_list()
|
||||
|
||||
# Short circuit if no changes to the play queue
|
||||
if (
|
||||
if not force and (
|
||||
self.current_play_queue == app_config.state.play_queue
|
||||
and self.current_playing_index == app_config.state.current_song_index
|
||||
):
|
||||
|
@@ -484,7 +484,6 @@ class PlaylistDetailPanel(Gtk.Overlay):
|
||||
self.playlist_artwork.get_style_context().remove_class("collapsed")
|
||||
self.playlist_name.get_style_context().remove_class("collapsed")
|
||||
self.playlist_box.show_all()
|
||||
self.playlist_artwork.set_image_size(200)
|
||||
self.playlist_indicator.set_markup("PLAYLIST")
|
||||
|
||||
if playlist.comment:
|
||||
@@ -499,7 +498,6 @@ class PlaylistDetailPanel(Gtk.Overlay):
|
||||
self.playlist_artwork.get_style_context().add_class("collapsed")
|
||||
self.playlist_name.get_style_context().add_class("collapsed")
|
||||
self.playlist_box.show_all()
|
||||
self.playlist_artwork.set_image_size(70)
|
||||
self.playlist_indicator.hide()
|
||||
self.playlist_comment.hide()
|
||||
self.playlist_stats.hide()
|
||||
@@ -576,6 +574,11 @@ class PlaylistDetailPanel(Gtk.Overlay):
|
||||
self.playlist_artwork.set_from_file(cover_art_filename)
|
||||
self.playlist_artwork.set_loading(False)
|
||||
|
||||
if self.playlist_details_expanded:
|
||||
self.playlist_artwork.set_image_size(200)
|
||||
else:
|
||||
self.playlist_artwork.set_image_size(70)
|
||||
|
||||
# Event Handlers
|
||||
# =========================================================================
|
||||
def on_view_refresh_click(self, _):
|
||||
|
Reference in New Issue
Block a user