Include custom attr table in database cleanup
This commit is contained in:
parent
41766cc0ac
commit
f1dbb84f61
@ -33,6 +33,7 @@ interface CustomAttributesRepository {
|
|||||||
suspend fun getAllTags(startsWith: String? = null): List<String>
|
suspend fun getAllTags(startsWith: String? = null): List<String>
|
||||||
fun getItemsForTag(tag: String): Flow<List<Searchable>>
|
fun getItemsForTag(tag: String): Flow<List<Searchable>>
|
||||||
fun addTag(item: Searchable, tag: String)
|
fun addTag(item: Searchable, tag: String)
|
||||||
|
suspend fun cleanupDatabase(): Int
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CustomAttributesRepositoryImpl(
|
internal class CustomAttributesRepositoryImpl(
|
||||||
@ -198,4 +199,14 @@ internal class CustomAttributesRepositoryImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun cleanupDatabase(): Int {
|
||||||
|
val dao = appDatabase.backupDao()
|
||||||
|
var removed = 0
|
||||||
|
val job = scope.launch {
|
||||||
|
removed = dao.cleanUp()
|
||||||
|
}
|
||||||
|
job.join()
|
||||||
|
return removed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -47,4 +47,7 @@ interface BackupRestoreDao {
|
|||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun importCustomAttributes(items: List<CustomAttributeEntity>)
|
suspend fun importCustomAttributes(items: List<CustomAttributeEntity>)
|
||||||
|
|
||||||
|
@Query("DELETE FROM CustomAttributes WHERE (type = 'tag' OR type = 'label') AND NOT EXISTS(SELECT 1 FROM Searchable WHERE CustomAttributes.key = Searchable.key)")
|
||||||
|
suspend fun cleanUp(): Int
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.settings.debug
|
|||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import de.mm20.launcher2.customattrs.CustomAttributesRepository
|
||||||
import de.mm20.launcher2.favorites.FavoritesRepository
|
import de.mm20.launcher2.favorites.FavoritesRepository
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
@ -9,8 +10,11 @@ import org.koin.core.component.inject
|
|||||||
|
|
||||||
class DebugSettingsScreenVM: ViewModel(), KoinComponent {
|
class DebugSettingsScreenVM: ViewModel(), KoinComponent {
|
||||||
|
|
||||||
val favoritesRepository: FavoritesRepository by inject()
|
private val favoritesRepository: FavoritesRepository by inject()
|
||||||
|
private val customAttributesRepository: CustomAttributesRepository by inject()
|
||||||
suspend fun cleanUpDatabase(): Int {
|
suspend fun cleanUpDatabase(): Int {
|
||||||
return favoritesRepository.cleanupDatabase()
|
var removed = favoritesRepository.cleanupDatabase()
|
||||||
|
removed += customAttributesRepository.cleanupDatabase()
|
||||||
|
return removed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user