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