Skip to content

Commit

Permalink
Add performance documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed Jun 18, 2022
1 parent c91dd6e commit c816ac1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions docs/best_practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c816ac1

Please sign in to comment.