mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-23 11:32:32 +01:00
refactor checkpointing
This commit is contained in:
parent
c6b062a698
commit
3e1e07e468
@ -1,8 +1,10 @@
|
|||||||
package org.schabi.newpipe;
|
package org.schabi.newpipe;
|
||||||
|
|
||||||
import androidx.room.Room;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.room.Room;
|
||||||
|
|
||||||
import org.schabi.newpipe.database.AppDatabase;
|
import org.schabi.newpipe.database.AppDatabase;
|
||||||
|
|
||||||
@ -39,4 +41,14 @@ public final class NewPipeDatabase {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkpoint() {
|
||||||
|
if(null == databaseInstance){
|
||||||
|
throw new IllegalStateException("database is not initialized");
|
||||||
|
}
|
||||||
|
Cursor c = databaseInstance.query("pragma wal_checkpoint(full)", null);
|
||||||
|
if(c.moveToFirst() && c.getInt(0) == 1) {
|
||||||
|
throw new RuntimeException("Checkpoint was blocked from completing");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import android.app.AlertDialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -18,7 +17,6 @@ import androidx.preference.Preference;
|
|||||||
import com.nononsenseapps.filepicker.Utils;
|
import com.nononsenseapps.filepicker.Utils;
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
|
|
||||||
import org.schabi.newpipe.App;
|
|
||||||
import org.schabi.newpipe.NewPipeDatabase;
|
import org.schabi.newpipe.NewPipeDatabase;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
@ -172,7 +170,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||||||
private void exportDatabase(String path) {
|
private void exportDatabase(String path) {
|
||||||
try {
|
try {
|
||||||
//checkpoint before export
|
//checkpoint before export
|
||||||
checkpoint();
|
NewPipeDatabase.checkpoint();
|
||||||
|
|
||||||
ZipOutputStream outZip = new ZipOutputStream(
|
ZipOutputStream outZip = new ZipOutputStream(
|
||||||
new BufferedOutputStream(
|
new BufferedOutputStream(
|
||||||
@ -191,12 +189,6 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkpoint() {
|
|
||||||
Cursor c = NewPipeDatabase.getInstance(App.getApp()).getOpenHelper().getWritableDatabase().query("pragma wal_checkpoint(full)");
|
|
||||||
if(c.moveToFirst() && c.getInt(0) == 1)
|
|
||||||
throw new RuntimeException("Checkpoint was blocked from completing");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveSharedPreferencesToFile(File dst) {
|
private void saveSharedPreferencesToFile(File dst) {
|
||||||
ObjectOutputStream output = null;
|
ObjectOutputStream output = null;
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user