Commit 75fc857d authored by Lixin Yue's avatar Lixin Yue Committed by Jaikumar Ganesh
Browse files

optimize deleting operation in trimDatabase()

parent df25af65
......@@ -904,18 +904,13 @@ public class BluetoothOppService extends Service {
int recordNum = cursor.getCount();
if (recordNum > Constants.MAX_RECORDS_IN_DATABASE) {
int numToDelete = recordNum - Constants.MAX_RECORDS_IN_DATABASE;
if (cursor.moveToFirst()) {
if (cursor.moveToPosition(numToDelete)) {
int columnId = cursor.getColumnIndexOrThrow(BluetoothShare._ID);
while (numToDelete > 0) {
getContentResolver().delete(
ContentUris.withAppendedId(BluetoothShare.CONTENT_URI, cursor
.getLong(columnId)), null, null);
if (V) Log.v(TAG, "Deleted old inbound success share.");
if (!cursor.moveToNext()) {
break;
}
numToDelete--;
}
long id = cursor.getLong(columnId);
delNum = getContentResolver().delete(BluetoothShare.CONTENT_URI,
BluetoothShare._ID + " < " + id, null);
if (V) Log.v(TAG, "Deleted old inbound success share: " + delNum);
}
}
cursor.close();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment