forked from upstream-mirrors/OpenTracks
Adding vacuum call for when a track is deleted (helps reclaim storage space).
This commit is contained in:
@@ -193,12 +193,14 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
@Override
|
@Override
|
||||||
public int delete(Uri url, String where, String[] selectionArgs) {
|
public int delete(Uri url, String where, String[] selectionArgs) {
|
||||||
String table;
|
String table;
|
||||||
|
boolean shouldVacuum = false;
|
||||||
switch (urlMatcher.match(url)) {
|
switch (urlMatcher.match(url)) {
|
||||||
case TRACKPOINTS:
|
case TRACKPOINTS:
|
||||||
table = TRACKPOINTS_TABLE;
|
table = TRACKPOINTS_TABLE;
|
||||||
break;
|
break;
|
||||||
case TRACKS:
|
case TRACKS:
|
||||||
table = TRACKS_TABLE;
|
table = TRACKS_TABLE;
|
||||||
|
shouldVacuum = true;
|
||||||
break;
|
break;
|
||||||
case WAYPOINTS:
|
case WAYPOINTS:
|
||||||
table = WAYPOINTS_TABLE;
|
table = WAYPOINTS_TABLE;
|
||||||
@@ -210,6 +212,13 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
Log.w(MyTracksProvider.TAG, "provider delete in " + table + "!");
|
Log.w(MyTracksProvider.TAG, "provider delete in " + table + "!");
|
||||||
int count = db.delete(table, where, selectionArgs);
|
int count = db.delete(table, where, selectionArgs);
|
||||||
getContext().getContentResolver().notifyChange(url, null, true);
|
getContext().getContentResolver().notifyChange(url, null, true);
|
||||||
|
|
||||||
|
if (shouldVacuum) {
|
||||||
|
// If a potentially large amount of data was deleted, we want to reclaim its space.
|
||||||
|
Log.i(TAG, "Vacuuming the database");
|
||||||
|
db.execSQL("VACUUM");
|
||||||
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user