1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Sync database optimizations

* enable WAL as early as possible
* don't close database in SyncAdapter but only in SyncService
* version bump to 1.0.4
This commit is contained in:
Ricki Hirner 2016-03-31 13:56:08 +02:00
parent c6aed90c96
commit fa528a64e9
6 changed files with 23 additions and 35 deletions

View File

@ -17,8 +17,8 @@ android {
minSdkVersion 14
targetSdkVersion 22
versionCode 93
versionName "1.0.3"
versionCode 94
versionName "1.0.4"
buildConfigField "long", "buildTime", System.currentTimeMillis() + "L"
}

View File

@ -72,15 +72,21 @@ public class ServiceDB {
public OpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
setWriteAheadLoggingEnabled(true);
}
@Override
public void onOpen(SQLiteDatabase db) {
db.enableWriteAheadLogging();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
db.setForeignKeyConstraintsEnabled(true);
else
else {
if (!db.enableWriteAheadLogging())
App.log.warning("Couldn't enable write-ahead logging");
db.execSQL("PRAGMA foreign_keys=ON;");
}
}
@Override

View File

@ -8,18 +8,14 @@
package at.bitfire.davdroid.syncadapter;
import android.accounts.Account;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.CalendarContract;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -32,7 +28,6 @@ import at.bitfire.davdroid.App;
import at.bitfire.davdroid.InvalidAccountException;
import at.bitfire.davdroid.model.CollectionInfo;
import at.bitfire.davdroid.model.ServiceDB.Collections;
import at.bitfire.davdroid.model.ServiceDB.OpenHelper;
import at.bitfire.davdroid.model.ServiceDB.Services;
import at.bitfire.davdroid.resource.LocalCalendar;
import at.bitfire.ical4android.CalendarStorageException;
@ -43,14 +38,14 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
@Override
public void onCreate() {
super.onCreate();
syncAdapter = new SyncAdapter(this, dbHelper);
syncAdapter = new SyncAdapter(this, dbHelper.getReadableDatabase());
}
private static class SyncAdapter extends SyncAdapterService.SyncAdapter {
public SyncAdapter(Context context, OpenHelper dbHelper) {
super(context, dbHelper);
public SyncAdapter(Context context, SQLiteDatabase db) {
super(context, db);
}
@Override

View File

@ -8,31 +8,24 @@
package at.bitfire.davdroid.syncadapter;
import android.accounts.Account;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;
import java.util.logging.Level;
import at.bitfire.davdroid.AccountSettings;
import at.bitfire.davdroid.App;
import at.bitfire.davdroid.InvalidAccountException;
import at.bitfire.davdroid.model.CollectionInfo;
import at.bitfire.davdroid.model.ServiceDB;
import at.bitfire.davdroid.model.ServiceDB.Collections;
import at.bitfire.davdroid.model.ServiceDB.OpenHelper;
import lombok.Cleanup;
public class ContactsSyncAdapterService extends SyncAdapterService {
@ -40,14 +33,14 @@ public class ContactsSyncAdapterService extends SyncAdapterService {
@Override
public void onCreate() {
super.onCreate();
syncAdapter = new ContactsSyncAdapter(this, dbHelper);
syncAdapter = new ContactsSyncAdapter(this, dbHelper.getReadableDatabase());
}
private static class ContactsSyncAdapter extends SyncAdapter {
public ContactsSyncAdapter(Context context, OpenHelper dbHelper) {
super(context, dbHelper);
public ContactsSyncAdapter(Context context, SQLiteDatabase db) {
super(context, db);
}
@Override

View File

@ -50,11 +50,12 @@ public abstract class SyncAdapterService extends Service {
public static abstract class SyncAdapter extends AbstractThreadedSyncAdapter {
protected final SQLiteDatabase db;
public SyncAdapter(Context context, ServiceDB.OpenHelper dbHelper) {
protected final SQLiteDatabase db; // will be closed in SyncAdapterService::onDestroy(), don't close manually!
public SyncAdapter(Context context, SQLiteDatabase db) {
super(context, false);
db = dbHelper.getReadableDatabase();
this.db = db;
}
@Override

View File

@ -8,18 +8,14 @@
package at.bitfire.davdroid.syncadapter;
import android.accounts.Account;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -31,7 +27,6 @@ import at.bitfire.davdroid.App;
import at.bitfire.davdroid.InvalidAccountException;
import at.bitfire.davdroid.model.CollectionInfo;
import at.bitfire.davdroid.model.ServiceDB.Collections;
import at.bitfire.davdroid.model.ServiceDB.OpenHelper;
import at.bitfire.davdroid.model.ServiceDB.Services;
import at.bitfire.davdroid.resource.LocalTaskList;
import at.bitfire.ical4android.CalendarStorageException;
@ -43,14 +38,14 @@ public class TasksSyncAdapterService extends SyncAdapterService {
@Override
public void onCreate() {
super.onCreate();
syncAdapter = new SyncAdapter(this, dbHelper);
syncAdapter = new SyncAdapter(this, dbHelper.getReadableDatabase());
}
private static class SyncAdapter extends SyncAdapterService.SyncAdapter {
public SyncAdapter(Context context, OpenHelper dbHelper) {
super(context, dbHelper);
public SyncAdapter(Context context, SQLiteDatabase db) {
super(context, db);
}
@Override
@ -73,8 +68,6 @@ public class TasksSyncAdapterService extends SyncAdapterService {
App.log.log(Level.SEVERE, "Couldn't enumerate local task lists", e);
} catch (InvalidAccountException e) {
App.log.log(Level.SEVERE, "Couldn't get account settings", e);
} finally {
db.close();
}
App.log.info("Task sync complete");