Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

optimize deleting operation in trimDatabase()

parent 81992d6c
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -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();