music: make file tree cache configurable
This commit is contained in:
@@ -29,6 +29,7 @@ import kotlinx.coroutines.withContext
|
|||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.oxycblt.auxio.image.covers.SettingCovers
|
import org.oxycblt.auxio.image.covers.SettingCovers
|
||||||
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
|
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
|
||||||
|
import org.oxycblt.auxio.music.shim.NoOpFileTreeCache
|
||||||
import org.oxycblt.auxio.music.shim.WriteOnlyFileTreeCache
|
import org.oxycblt.auxio.music.shim.WriteOnlyFileTreeCache
|
||||||
import org.oxycblt.auxio.music.shim.WriteOnlyMutableCache
|
import org.oxycblt.auxio.music.shim.WriteOnlyMutableCache
|
||||||
import org.oxycblt.musikr.IndexingProgress
|
import org.oxycblt.musikr.IndexingProgress
|
||||||
@@ -396,8 +397,12 @@ constructor(
|
|||||||
val cache = if (withCache) cache else WriteOnlyMutableCache(cache)
|
val cache = if (withCache) cache else WriteOnlyMutableCache(cache)
|
||||||
val covers = settingCovers.mutate(context, newRevision)
|
val covers = settingCovers.mutate(context, newRevision)
|
||||||
val fileTreeCache =
|
val fileTreeCache =
|
||||||
if (withCache) FileTreeCache.from(context)
|
if (musicSettings.useFileTreeCache) {
|
||||||
else WriteOnlyFileTreeCache(FileTreeCache.from(context))
|
if (withCache) FileTreeCache.from(context)
|
||||||
|
else WriteOnlyFileTreeCache(FileTreeCache.from(context))
|
||||||
|
} else {
|
||||||
|
NoOpFileTreeCache()
|
||||||
|
}
|
||||||
val query = Query(source = locations, exclude = excludedLocations)
|
val query = Query(source = locations, exclude = excludedLocations)
|
||||||
val storage = Storage(cache, covers, storedPlaylists, fileTreeCache)
|
val storage = Storage(cache, covers, storedPlaylists, fileTreeCache)
|
||||||
val interpretation = Interpretation(nameFactory, separators, withHidden)
|
val interpretation = Interpretation(nameFactory, separators, withHidden)
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
|||||||
var separators: String
|
var separators: String
|
||||||
/** Whether to enable more advanced sorting by articles and numbers. */
|
/** Whether to enable more advanced sorting by articles and numbers. */
|
||||||
val intelligentSorting: Boolean
|
val intelligentSorting: Boolean
|
||||||
|
/** Whether to use the file-system cache for improved loading times. */
|
||||||
|
val useFileTreeCache: Boolean
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
/** Called when the current music locations changed. */
|
/** Called when the current music locations changed. */
|
||||||
@@ -133,6 +135,9 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
|||||||
override val intelligentSorting: Boolean
|
override val intelligentSorting: Boolean
|
||||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_auto_sort_names), true)
|
get() = sharedPreferences.getBoolean(getString(R.string.set_key_auto_sort_names), true)
|
||||||
|
|
||||||
|
override val useFileTreeCache: Boolean
|
||||||
|
get() = sharedPreferences.getBoolean(getString(R.string.set_key_fs_cache), true)
|
||||||
|
|
||||||
override fun onSettingChanged(key: String, listener: MusicSettings.Listener) {
|
override fun onSettingChanged(key: String, listener: MusicSettings.Listener) {
|
||||||
// TODO: Differentiate "hard reloads" (Need the cache) and "Soft reloads"
|
// TODO: Differentiate "hard reloads" (Need the cache) and "Soft reloads"
|
||||||
// (just need to manipulate data)
|
// (just need to manipulate data)
|
||||||
@@ -145,7 +150,8 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
|
|||||||
getString(R.string.set_key_separators),
|
getString(R.string.set_key_separators),
|
||||||
getString(R.string.set_key_auto_sort_names),
|
getString(R.string.set_key_auto_sort_names),
|
||||||
getString(R.string.set_key_with_hidden),
|
getString(R.string.set_key_with_hidden),
|
||||||
getString(R.string.set_key_exclude_non_music) -> {
|
getString(R.string.set_key_exclude_non_music),
|
||||||
|
getString(R.string.set_key_fs_cache) -> {
|
||||||
L.d("Dispatching indexing setting change for $key")
|
L.d("Dispatching indexing setting change for $key")
|
||||||
listener.onIndexingSettingChanged()
|
listener.onIndexingSettingChanged()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Auxio Project
|
||||||
|
* NoOpFileTreeCache.kt is part of Auxio.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.oxycblt.auxio.music.shim
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import org.oxycblt.musikr.fs.device.CachedDirectory
|
||||||
|
import org.oxycblt.musikr.fs.device.CachedFile
|
||||||
|
import org.oxycblt.musikr.fs.device.FileTree
|
||||||
|
import org.oxycblt.musikr.fs.device.FileTreeCache
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-op implementation of [FileTreeCache] that doesn't cache anything. This implementation always
|
||||||
|
* returns cache misses and discards all updates.
|
||||||
|
*/
|
||||||
|
class NoOpFileTreeCache : FileTreeCache {
|
||||||
|
override fun read(): FileTree = NoOpFileTree()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-op implementation of [FileTree] that doesn't cache anything. All queries return null (cache
|
||||||
|
* miss) and all updates are discarded.
|
||||||
|
*/
|
||||||
|
class NoOpFileTree : FileTree {
|
||||||
|
override suspend fun queryDirectory(uri: Uri): CachedDirectory? {
|
||||||
|
// Always return null to simulate a cache miss
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateDirectory(uri: Uri, directory: CachedDirectory) {
|
||||||
|
// Do nothing - discard the update
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun queryFile(uri: Uri): CachedFile? {
|
||||||
|
// Always return null to simulate a cache miss
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateFile(uri: Uri, file: CachedFile) {
|
||||||
|
// Do nothing - discard the update
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun write() {
|
||||||
|
// Do nothing - no cache to write
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
<string name="set_key_observing" translatable="false">auxio_observing</string>
|
<string name="set_key_observing" translatable="false">auxio_observing</string>
|
||||||
<string name="set_key_music_dirs" translatable="false">auxio_music_dirs</string>
|
<string name="set_key_music_dirs" translatable="false">auxio_music_dirs</string>
|
||||||
<string name="set_key_excluded_dirs" translatable="false">auxio_excluded_dirs</string>
|
<string name="set_key_excluded_dirs" translatable="false">auxio_excluded_dirs</string>
|
||||||
|
<string name="set_key_fs_cache" translatable="false">auxio_fs_cache</string>
|
||||||
<string name="set_key_cover_mode" translatable="false">auxio_cover_mode2</string>
|
<string name="set_key_cover_mode" translatable="false">auxio_cover_mode2</string>
|
||||||
<string name="set_key_square_covers" translatable="false">auxio_square_covers</string>
|
<string name="set_key_square_covers" translatable="false">auxio_square_covers</string>
|
||||||
<string name="set_key_exclude_non_music" translatable="false">auxio_exclude_non_music</string>
|
<string name="set_key_exclude_non_music" translatable="false">auxio_exclude_non_music</string>
|
||||||
|
|||||||
@@ -315,6 +315,8 @@
|
|||||||
<string name="set_locations">Music folders</string>
|
<string name="set_locations">Music folders</string>
|
||||||
<string name="set_locations_desc">Manage where music should be loaded from</string>
|
<string name="set_locations_desc">Manage where music should be loaded from</string>
|
||||||
<string name="set_locations_new">New folder</string>
|
<string name="set_locations_new">New folder</string>
|
||||||
|
<string name="set_fs_cache">Use file-system cache</string>
|
||||||
|
<string name="set_fs_cache_desc">Improves loading times, but can prevent new music from being added</string>
|
||||||
<string name="set_excluded_locations">Excluded folders</string>
|
<string name="set_excluded_locations">Excluded folders</string>
|
||||||
<string name="set_excluded_locations_desc">Manage folders to exclude from music loading</string>
|
<string name="set_excluded_locations_desc">Manage folders to exclude from music loading</string>
|
||||||
<string name="set_reindex">Refresh music</string>
|
<string name="set_reindex">Refresh music</string>
|
||||||
|
|||||||
@@ -33,6 +33,11 @@
|
|||||||
app:summary="@string/set_locations_desc"
|
app:summary="@string/set_locations_desc"
|
||||||
app:title="@string/set_locations" />
|
app:title="@string/set_locations" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
app:key="@string/set_key_fs_cache"
|
||||||
|
app:summary="@string/set_fs_cache_desc"
|
||||||
|
app:title="@string/set_fs_cache" />
|
||||||
|
|
||||||
<org.oxycblt.auxio.settings.ui.WrappedDialogPreference
|
<org.oxycblt.auxio.settings.ui.WrappedDialogPreference
|
||||||
app:key="@string/set_key_excluded_dirs"
|
app:key="@string/set_key_excluded_dirs"
|
||||||
app:summary="@string/set_excluded_locations_desc"
|
app:summary="@string/set_excluded_locations_desc"
|
||||||
|
|||||||
Reference in New Issue
Block a user