diff --git a/docs/best_practices.md b/docs/best_practices.md index 9edfbce..7792d8f 100644 --- a/docs/best_practices.md +++ b/docs/best_practices.md @@ -2,6 +2,17 @@ This page contains best practices when using the API to ensure the best UX possi ## Performance considerations +### Only request the ContactColumns you need + +Each [ContactColumn]() requested via the `ContactStore#fetchContacts()` function is going to cause +additional database queries to take place. This can cause increase loading times. It is advices to only request the ContactColumns +you need at any given point. + +Keep in mind that you might have access to the information you need without requesting for any columns. + +If you are building a list of contacts and you need to display their names, +use [Contact#displayName]() instead of requesting for the [ContactColumn.Names]() column. For the same scenario, use the [Contact.thumbnailUri]() instead of querying for the [ContactColumn.Image] column, if you do no need a high-res version of the contact image. + ### Use a Predicate to quickly resolve phone numbers Instead of fetching all contacts' phone numbers and try to find the contact containing a phone diff --git a/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt b/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt index 36c1798..07484ff 100644 --- a/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt +++ b/library/src/main/java/com/alexstyl/contactstore/ContactColumn.kt @@ -31,7 +31,8 @@ public sealed class ContactColumn { /** * A column that will populate the [Contact.imageData] field of all queried contacts when requested. * - * @see Contact.imageData + * + * *NOTE*: You do not need this column if you do not need a high-res image of contacts. Use [Contact.thumbnailUri] instead. */ public object Image : ContactColumn() @@ -46,7 +47,7 @@ public sealed class ContactColumn { * * [Contact.phoneticMiddleName] * * [Contact.phoneticLastName] * - * + * *NOTE*: You do not need this column if you only need access to the display name of contacts (for use in a contact list for example). Use [Contact.displayName] instead. */ public object Names : ContactColumn() diff --git a/library/src/main/java/com/alexstyl/contactstore/ContactStore.kt b/library/src/main/java/com/alexstyl/contactstore/ContactStore.kt index 099b433..e6782b5 100644 --- a/library/src/main/java/com/alexstyl/contactstore/ContactStore.kt +++ b/library/src/main/java/com/alexstyl/contactstore/ContactStore.kt @@ -27,7 +27,7 @@ public interface ContactStore { * Returns a [FetchRequest] that emits all contacts matching the given [predicate] when collected. * * @param predicate The conditions that a contact need to meet in order to be fetched - * @param columnsToFetch The columns of the contact you need to be fetched + * @param columnsToFetch The columns of the contact you need to be fetched. * @param displayNameStyle The preferred style for the [Contact.displayName] to be returned. The fetched contacts' sorting order will match this option. */ public fun fetchContacts(