use projection to gain 25% of time
This commit is contained in:
parent
327a596de5
commit
f714566200
|
@ -21,7 +21,9 @@ import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
class ContactsDataSource @Inject constructor(
|
class ContactsDataSource @Inject constructor(
|
||||||
private val context: Context
|
private val context: Context
|
||||||
|
@ -32,19 +34,14 @@ class ContactsDataSource @Inject constructor(
|
||||||
val result = mutableListOf<MappedContact>()
|
val result = mutableListOf<MappedContact>()
|
||||||
val contentResolver = context.contentResolver
|
val contentResolver = context.contentResolver
|
||||||
|
|
||||||
|
measureTimeMillis {
|
||||||
contentResolver.query(
|
contentResolver.query(
|
||||||
ContactsContract.Contacts.CONTENT_URI,
|
ContactsContract.Contacts.CONTENT_URI,
|
||||||
null,
|
|
||||||
/* TODO
|
|
||||||
arrayOf(
|
arrayOf(
|
||||||
ContactsContract.Contacts._ID,
|
ContactsContract.Contacts._ID,
|
||||||
ContactsContract.Data.DISPLAY_NAME,
|
ContactsContract.Data.DISPLAY_NAME,
|
||||||
ContactsContract.Data.PHOTO_URI,
|
ContactsContract.Data.PHOTO_URI
|
||||||
ContactsContract.Data.MIMETYPE,
|
|
||||||
ContactsContract.CommonDataKinds.Phone.NUMBER,
|
|
||||||
ContactsContract.CommonDataKinds.Email.ADDRESS
|
|
||||||
),
|
),
|
||||||
*/
|
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
// Sort by Display name
|
// Sort by Display name
|
||||||
|
@ -67,7 +64,9 @@ class ContactsDataSource @Inject constructor(
|
||||||
|
|
||||||
// Get the phone numbers
|
// Get the phone numbers
|
||||||
contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||||
null,
|
arrayOf(
|
||||||
|
ContactsContract.CommonDataKinds.Phone.NUMBER
|
||||||
|
),
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
|
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
|
||||||
arrayOf(id.toString()),
|
arrayOf(id.toString()),
|
||||||
null)
|
null)
|
||||||
|
@ -88,7 +87,9 @@ class ContactsDataSource @Inject constructor(
|
||||||
// Get Emails
|
// Get Emails
|
||||||
contentResolver.query(
|
contentResolver.query(
|
||||||
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
||||||
null,
|
arrayOf(
|
||||||
|
ContactsContract.CommonDataKinds.Email.DATA
|
||||||
|
),
|
||||||
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
|
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
|
||||||
arrayOf(id.toString()),
|
arrayOf(id.toString()),
|
||||||
null)
|
null)
|
||||||
|
@ -112,6 +113,7 @@ class ContactsDataSource @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.also { Timber.d("Took ${it}ms to fetch ${result.size} contact(s)") }
|
||||||
|
|
||||||
return result
|
return result
|
||||||
.filter { it.emails.isNotEmpty() || it.msisdns.isNotEmpty() }
|
.filter { it.emails.isNotEmpty() || it.msisdns.isNotEmpty() }
|
||||||
|
|
Loading…
Reference in New Issue