Add preference for SQLite "synchronous" flag
By default SQLite runs with synchronous=FULL, which is the safest mode and uses fsync() a lot, but this interacts very badly with Samsung's infamous RFS filesystem. With this preference the user can decide whether to sacrifice some safety for reasonable performance.
This commit is contained in:
parent
24aa230f14
commit
176c9173ae
@ -7,7 +7,6 @@
|
||||
<item>Every 12 Hours</item>
|
||||
<item>Daily</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="updateIntervalValues">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
@ -16,4 +15,14 @@
|
||||
<item>24</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dbSyncModeNames">
|
||||
<item>Off (unsafe)</item>
|
||||
<item>Normal</item>
|
||||
<item>Full</item>
|
||||
</string-array>
|
||||
<string-array name="dbSyncModeValues">
|
||||
<item>off</item>
|
||||
<item>normal</item>
|
||||
<item>full</item>
|
||||
</string-array>
|
||||
</resources>
|
@ -124,4 +124,7 @@
|
||||
<string name="expert_mode">Enable expert mode</string>
|
||||
|
||||
<string name="search_hint">Search applications</string>
|
||||
|
||||
<string name="db_sync_mode">Database sync mode</string>
|
||||
<string name="db_sync_mode_long">Set the value of SQLite\'s "synchronous" flag</string>
|
||||
</resources>
|
||||
|
@ -4,6 +4,10 @@
|
||||
<CheckBoxPreference android:title="@string/cache_downloaded"
|
||||
android:defaultValue="false" android:summary="@string/keep_downloaded"
|
||||
android:key="cacheDownloaded" />
|
||||
<ListPreference android:title="@string/db_sync_mode"
|
||||
android:summary="@string/db_sync_mode_long" android:key="dbSyncMode"
|
||||
android:defaultValue="full" android:entries="@array/dbSyncModeNames"
|
||||
android:entryValues="@array/dbSyncModeValues" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/updates">
|
||||
<ListPreference android:title="@string/automatic_repo_scan"
|
||||
|
@ -39,6 +39,11 @@ public class DB {
|
||||
|
||||
private static final String DATABASE_NAME = "fdroid";
|
||||
|
||||
// Possible values of the SQLite flag "synchronous"
|
||||
public static final int SYNC_OFF = 0;
|
||||
public static final int SYNC_NORMAL = 1;
|
||||
public static final int SYNC_FULL = 2;
|
||||
|
||||
private SQLiteDatabase db;
|
||||
|
||||
// The TABLE_APP table stores details of all the applications we know about.
|
||||
@ -266,6 +271,19 @@ public class DB {
|
||||
DBHelper h = new DBHelper(ctx);
|
||||
db = h.getWritableDatabase();
|
||||
mPm = ctx.getPackageManager();
|
||||
SharedPreferences prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(mContext);
|
||||
String sync_mode = prefs.getString("dbSyncMode", null);
|
||||
if ("off".equals(sync_mode))
|
||||
setSynchronizationMode(SYNC_OFF);
|
||||
else if ("normal".equals(sync_mode))
|
||||
setSynchronizationMode(SYNC_NORMAL);
|
||||
else if ("full".equals(sync_mode))
|
||||
setSynchronizationMode(SYNC_FULL);
|
||||
else
|
||||
sync_mode = null;
|
||||
if (sync_mode != null)
|
||||
Log.d("FDroid", "Database synchronization mode: " + sync_mode);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@ -683,4 +701,16 @@ public class DB {
|
||||
db.delete(TABLE_REPO, "address = ?", new String[] { address });
|
||||
}
|
||||
}
|
||||
|
||||
public int getSynchronizationMode() {
|
||||
Cursor cursor = db.rawQuery("PRAGMA synchronous", null);
|
||||
cursor.moveToFirst();
|
||||
int mode = cursor.getInt(0);
|
||||
cursor.close();
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setSynchronizationMode(int mode) {
|
||||
db.execSQL("PRAGMA synchronous = " + mode);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user