Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realme RMX2151 (Realme 7) - LIMIT and OFFSET APIs are not working #241

Closed
atharv-appyhigh opened this issue Jun 28, 2022 · 5 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@atharv-appyhigh
Copy link

I want to implement pagination for showing the contacts to those user who have thousand's of Contacts, I wanted to use the limit and offset functionality, but they don't work in version 0.2.1 and also 0.2.2, can you please fix them

Screenshot 2022-06-28 at 12 15 11

?
@vestrel00
Copy link
Owner

vestrel00 commented Jun 28, 2022

@atharv-appyhigh, thanks for creating this issue and taking interest in using this library!

I thought I fixed this issue in release 0.2.1. This seems to be a duplicate of #217.

I will take a look at it again tomorrow morning (it's late here). This is high priority and if I'm able to reproduce it I will work on a patch ASAP!

While you wait, please tell me some details about the device you are testing on. Is it an emulator? What API level is it?

@atharv-appyhigh
Copy link
Author

Hi @vestrel00, first of all Thanks for creating such an amazing library, I have have looked at other feature and I was blown away by them😉.

Regarding this issue, I have tested both the release 0.2.1 and also release 0.2.2 but none of them seems to address the problem, I also looked at #217 before posting it again because it didn't solve the problem.

I am currently testing on "Realme RMX2151 (Realme 7)" with Api level 30 (android 11). I tested it with both BroadQuery and Query, but both of them return all of the contacts regardless of the offset and limit parameter I use.

Thank you again for the library man

@vestrel00
Copy link
Owner

Thanks for creating such an amazing library, I have have looked at other feature and I was blown away by them😉

Thanks! This praise is amazing! I'll sleep good tonight 😁

Thank you again for the library man

It's my pleasure and thank you for using it!

I am currently testing on "Realme RMX2151 (Realme 7)" with Api level 30 (android 11

Could you please test on a google pixel emulator? See if you can reproduce the issue there. Hopefully, it is reproducible there so I can repro it myself 🙏

@vestrel00 vestrel00 self-assigned this Jun 28, 2022
@vestrel00 vestrel00 added the bug Something isn't working label Jun 28, 2022
@vestrel00 vestrel00 added this to Waiting for reply in Consumer issues Jun 28, 2022
@vestrel00 vestrel00 moved this from Waiting for reply to In progress in Consumer issues Jun 28, 2022
@vestrel00
Copy link
Owner

vestrel00 commented Jun 28, 2022

@atharv-appyhigh, I ran the following code using version 0.2.2.

Contacts(context).broadQuery().offset(25).limit(25).find()

I am not able to reproduce this issue in the following emulators;

  • Pixel 4 API 32 (Android 12)
  • Pixel 4 API 30 (Android 11)

I am also not able to reproduce it in real physical devices I own;

  • Samsung Galaxy A71 SM-A715f API 31 (Android 12)
  • Samsung Galaxy Tab S6 Lite SM-P610 API 31 (Android 12)
  • Nexus 6P API 27 (Android 8.1)

Could you please see if you can reproduce this issue in an emulator or any other device?

Otherwise, this issue is probably specific to "Realme RMX2151 (Realme 7)" or the Realme phones in general. I don't own a Realme phone and Genymotion does not have an image of any Realme devices, so I will need your help in debugging this issue 🙏

Could you look at the error logs and see if you see anything relevant there when you are executing your query? Otherwise, just copy-paste the entire logs and I'll look through it myself. Make sure that you do NOT include private data that you don't want to be public in the internet. So, I recommend using fake test data/contacts for this.

Also, please run the following code and share the log output. This will determine whether or not this is a bug with this library or if it is a limitation from the Realme phone.

val cursor1 = contentResolver.query(
    ContactsContract.Contacts.CONTENT_URI,
    arrayOf(ContactsContract.Contacts._ID),
    null,
    null,
    "_id COLLATE NOCASE ASC LIMIT 25 OFFSET 25"
)
val cursor2 = contentResolver.query(
    ContactsContract.Contacts.CONTENT_URI,
    arrayOf(ContactsContract.Contacts._ID),
    null,
    null,
    "_id ASC LIMIT 25 OFFSET 25"
)
val cursor3 = contentResolver.query(
    ContactsContract.Contacts.CONTENT_URI,
    arrayOf(ContactsContract.Contacts._ID),
    null,
    null,
    "_id ASC LIMIT 25"
)
val cursor4 = contentResolver.query(
    ContactsContract.Contacts.CONTENT_URI,
    arrayOf(ContactsContract.Contacts._ID),
    null,
    null,
    "_id LIMIT 25"
)


Log.d(
    "ContactsDebug",
    """
        cursor1: ${cursor1?.count}
        cursor2: ${cursor2?.count}
        cursor3: ${cursor3?.count}
        cursor4: ${cursor4?.count}
    """.trimIndent()
)

In the meantime, you could optimize your query by a LOT even if pagination does not work for certain devices you are targeting. If you only need to show the display name of contacts in a list, make sure to only include the Fields.Contact.DisplayNamePrimary. In general, including only fields from Fields.Contact will result in an optimized query.

So, your code would look something like;

Contacts(context)
        .broadQuery()
        .include(Fields.Contact.DisplayNamePrimary)
        .offset(25)
        .limit(25)
        .findWithContext()

The above query should run in less than 1-2 seconds in mid-range devices for 10,000 contacts.

ℹ️ Read more about include() in https://vestrel00.github.io/contacts-android/entities/include-only-desired-data/

I recommend to keep using offset and limit even if they don't work for some devices. If we are unable to fix this issue for Realme phones, I will add a property to query Results that indicates whether limit was supported/respected. The code would be equivalent to the following, which you can use right now,

val isLimitBreached = result.size > limit

When you need to show all data of one contact, you can do;

Contacts(context)
        .query()
        .where { Contact.Id equalTo contact.id }
        .findWithContext()
        .firstOrNull()

ℹ️ Read more about query() and where in https://vestrel00.github.io/contacts-android/basics/query-contacts-advanced/#a-basic-query

The list -> detail pattern is typically used in all Contacts apps (AOSP Contacts, Google Contacts, Samsung Contacts, etc).

@vestrel00 vestrel00 changed the title LIMIT and OFFSET API's are not working LIMIT and OFFSET API's are not working in Realme RMX2151 (Realme 7) API 30 Jun 28, 2022
@vestrel00 vestrel00 moved this from In progress to Waiting for reply in Consumer issues Jun 28, 2022
@vestrel00 vestrel00 changed the title LIMIT and OFFSET API's are not working in Realme RMX2151 (Realme 7) API 30 Realme RMX2151 (Realme 7) API 30 - LIMIT and OFFSET APIs are not working Jun 28, 2022
@vestrel00 vestrel00 changed the title Realme RMX2151 (Realme 7) API 30 - LIMIT and OFFSET APIs are not working Realme RMX2151 (Realme 7) - LIMIT and OFFSET APIs are not working Jun 28, 2022
@atharv-appyhigh
Copy link
Author

I think that it is issue with realme Ui only, I have also tested it on my emulator with different API versions and also some physical devices, it is a bug of phone. I have followed your optimisation techniques and it's getting my job done. I don't know what kind of sh*t os is installed in this phone. Anyways, Thanks for the help and the library, I am greatful for people like you who exist in the community. 😌

This is the output from the code above:

Screenshot 2022-06-29 at 14 30 18

@vestrel00 vestrel00 moved this from Waiting for reply to Done in Consumer issues Jun 29, 2022
Repository owner locked and limited conversation to collaborators Jun 29, 2022
@vestrel00 vestrel00 converted this issue into discussion #242 Jun 29, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants