music: integrate filetreecache

This commit is contained in:
Alexander Capehart
2025-05-29 19:34:08 -06:00
parent ec4d003af8
commit d3a3533146
5 changed files with 79 additions and 15 deletions
@@ -30,6 +30,7 @@ import kotlinx.coroutines.yield
import org.oxycblt.auxio.image.covers.SettingCovers
import org.oxycblt.auxio.music.MusicRepository.IndexingWorker
import org.oxycblt.auxio.music.shim.WriteOnlyMutableCache
import org.oxycblt.auxio.music.shim.WriteOnlyFileTreeCache
import org.oxycblt.musikr.IndexingProgress
import org.oxycblt.musikr.Interpretation
import org.oxycblt.musikr.Library
@@ -39,6 +40,7 @@ import org.oxycblt.musikr.MutableLibrary
import org.oxycblt.musikr.Playlist
import org.oxycblt.musikr.Song
import org.oxycblt.musikr.Storage
import org.oxycblt.musikr.fs.device.FileTreeCache
import org.oxycblt.musikr.cache.MutableCache
import org.oxycblt.musikr.playlist.db.StoredPlaylists
import org.oxycblt.musikr.tag.interpret.Naming
@@ -391,7 +393,8 @@ constructor(
val newRevision = currentRevision?.takeIf { withCache } ?: UUID.randomUUID()
val cache = if (withCache) cache else WriteOnlyMutableCache(cache)
val covers = settingCovers.mutate(context, newRevision)
val storage = Storage(cache, covers, storedPlaylists)
val fileTreeCache = if (withCache) FileTreeCache.from(context) else WriteOnlyFileTreeCache(FileTreeCache.from(context))
val storage = Storage(cache, covers, storedPlaylists, fileTreeCache)
val interpretation = Interpretation(nameFactory, separators, withHidden)
val result =
Musikr.new(context, storage, interpretation).run(locations, ::emitIndexingProgress)
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2025 Auxio Project
* WriteOnlyFileTreeCache.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
class WriteOnlyFileTreeCache(private val inner: FileTreeCache) : FileTreeCache {
override fun read(): FileTree {
val innerTree = inner.read()
return WriteOnlyFileTree(innerTree)
}
}
class WriteOnlyFileTree(private val innerTree: FileTree) : 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) {
// Forward update operations to the inner tree
innerTree.updateDirectory(uri, directory)
}
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) {
// Forward update operations to the inner tree
innerTree.updateFile(uri, file)
}
override suspend fun write() {
// Forward write operations to the inner tree
innerTree.write()
}
}