Merge pull request #12816 from TeamNewPipe/dbFix

Minor fixes for database
This commit is contained in:
Stypox 2025-11-18 08:57:00 +01:00 committed by GitHub
commit b9160a8647
4 changed files with 9 additions and 21 deletions

View file

@ -1,13 +0,0 @@
/*
* SPDX-FileCopyrightText: 2017 NewPipe contributors <https://newpipe.net>
* SPDX-FileCopyrightText: 2025 NewPipe e.V. <https://newpipe-ev.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package org.schabi.newpipe.database.history.dao
import org.schabi.newpipe.database.BasicDAO
interface HistoryDAO<T> : BasicDAO<T> {
val latestEntry: T
}

View file

@ -9,13 +9,14 @@ package org.schabi.newpipe.database.history.dao
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Query import androidx.room.Query
import io.reactivex.rxjava3.core.Flowable import io.reactivex.rxjava3.core.Flowable
import org.schabi.newpipe.database.BasicDAO
import org.schabi.newpipe.database.history.model.SearchHistoryEntry import org.schabi.newpipe.database.history.model.SearchHistoryEntry
@Dao @Dao
interface SearchHistoryDAO : HistoryDAO<SearchHistoryEntry> { interface SearchHistoryDAO : BasicDAO<SearchHistoryEntry> {
@get:Query("SELECT * FROM search_history WHERE id = (SELECT MAX(id) FROM search_history)") @get:Query("SELECT * FROM search_history WHERE id = (SELECT MAX(id) FROM search_history)")
override val latestEntry: SearchHistoryEntry val latestEntry: SearchHistoryEntry?
@Query("DELETE FROM search_history") @Query("DELETE FROM search_history")
override fun deleteAll(): Int override fun deleteAll(): Int

View file

@ -10,15 +10,13 @@ import androidx.room.Dao
import androidx.room.Query import androidx.room.Query
import androidx.room.RewriteQueriesToDropUnusedColumns import androidx.room.RewriteQueriesToDropUnusedColumns
import io.reactivex.rxjava3.core.Flowable import io.reactivex.rxjava3.core.Flowable
import org.schabi.newpipe.database.BasicDAO
import org.schabi.newpipe.database.history.model.StreamHistoryEntity import org.schabi.newpipe.database.history.model.StreamHistoryEntity
import org.schabi.newpipe.database.history.model.StreamHistoryEntry import org.schabi.newpipe.database.history.model.StreamHistoryEntry
import org.schabi.newpipe.database.stream.StreamStatisticsEntry import org.schabi.newpipe.database.stream.StreamStatisticsEntry
@Dao @Dao
abstract class StreamHistoryDAO : HistoryDAO<StreamHistoryEntity> { abstract class StreamHistoryDAO : BasicDAO<StreamHistoryEntity> {
@get:Query("SELECT * FROM stream_history WHERE access_date = (SELECT MAX(access_date) FROM stream_history)")
abstract override val latestEntry: StreamHistoryEntity
@Query("SELECT * FROM stream_history") @Query("SELECT * FROM stream_history")
abstract override fun getAll(): Flowable<List<StreamHistoryEntity>> abstract override fun getAll(): Flowable<List<StreamHistoryEntity>>

View file

@ -40,6 +40,8 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class BackupRestoreSettingsFragment extends BasePreferenceFragment { public class BackupRestoreSettingsFragment extends BasePreferenceFragment {
@ -155,9 +157,9 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment {
} }
private void exportDatabase(final StoredFileHelper file, final Uri exportDataUri) { private void exportDatabase(final StoredFileHelper file, final Uri exportDataUri) {
try { try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
//checkpoint before export //checkpoint before export
NewPipeDatabase.checkpoint(); executor.submit(NewPipeDatabase::checkpoint).get();
final SharedPreferences preferences = PreferenceManager final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(requireContext()); .getDefaultSharedPreferences(requireContext());