<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    As usual, Albert was right :)<br>
    <br>
    We already have to do the second round of accesses one-by-one
    because the batch-access vcard API doesn't work. I had forgotten
    this.<br>
    <br>
    I have changed the lookup to be the way Albert suggested, where it
    either looks up the timestamp for all contacts without specifying
    each, or it looks up exactly one.<br>
    <br>
    Merge request:
    <a class="moz-txt-link-freetext" href="https://invent.kde.org/kde/kdeconnect-android/merge_requests/103">https://invent.kde.org/kde/kdeconnect-android/merge_requests/103</a><br>
    <br>
    <div class="moz-cite-prefix">On 10/17/19 9:38 PM, Simon Redman
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:3065fc58-3688-a7b5-192e-f50acf9e913f@ergotech.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      To explain another point that I think might be causing confusion:<br>
      I agree that the problem in this case is too many variables and
      not too many results. However, once we get the results from this
      function, it gets fed in to another function to get the actual
      data.<br>
      <br>
      <div class="moz-cite-prefix">On 10/17/19 9:31 PM, Simon Redman
        wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:751e38db-cc29-88f1-17e6-7371aab25ec5@ergotech.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        Batch accesses are faster than single accesses. I haven't tried
        it for contacts, but one time when I went to one-by-one access
        for SMS it was like 15x slower.<br>
        <br>
        On the other hand, I have thousands of text messages and only a
        couple hundred contacts, so the problem is less. My suggestion
        would be to break it in to batches of 75 (to pick a random
        number that I'm pretty sure is safe). Probably in
        ContactsHelper.getVCardsForContactIDs.<br>
        <br>
        I will try to do this this weekend but if someone else beats me
        to it I won't be hurt :)<br>
        <br>
        Thanks,<br>
        Simon<br>
        <br>
        <div class="moz-cite-prefix">On 10/16/19 10:15 AM, Albert Vaca
          Cintora wrote:<br>
        </div>
        <blockquote type="cite"
cite="mid:CAAQViEsGOJ7LDY2dzat9M6Uqa_3Myww=JMJ55KrF-fYOMWhtMg@mail.gmail.com">
          <meta http-equiv="content-type" content="text/html;
            charset=UTF-8">
          <div dir="auto">I don't see any use of this function that
            isn't with either a single contact or all the contacts
            (correct me if I'm wrong). The "too many variables" would be
            avoided by having a method that in the second case just
            doesn't use a "where in", because the problem is too many
            variables and not too many results. </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Mon, Oct 14, 2019,
              07:06 Simon Redman <<a href="mailto:simon@ergotech.com"
                moz-do-not-send="true">simon@ergotech.com</a>> wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div>Yes, probably we could do this. The trouble is that
                for the first time running synchronization the desktop
                would then call this method with the complete list of
                changed contacts. Since it is first sync, it would be
                all of them, thus it would have the same problem.<br>
                <br>
                So the simplest solution would be to just break it in to
                batches since this solves both cases. But what is a safe
                batch size?<br>
                <br>
                <div class="gmail_quote">On October 12, 2019 12:01:53 PM
                  PDT, Albert Vaca Cintora <<a
                    href="mailto:albertvaka@gmail.com" target="_blank"
                    rel="noreferrer" moz-do-not-send="true">albertvaka@gmail.com</a>>
                  wrote:
                  <blockquote class="gmail_quote" style="margin:0pt 0pt
                    0pt 0.8ex;border-left:1px solid
                    rgb(204,204,204);padding-left:1ex">
                    <pre>Or even, if we are requesting *all* the IDs, I guess we could remove
the `WHERE ID IN()` in that call?

On Sat, Oct 12, 2019 at 9:00 PM Albert Vaca Cintora
<<a href="mailto:albertvaka@gmail.com" target="_blank" rel="noreferrer" moz-do-not-send="true">albertvaka@gmail.com</a>> wrote:
<blockquote class="gmail_quote" style="margin:0pt 0pt 1ex 0.8ex;border-left:1px solid #729fcf;padding-left:1ex">
 Actually here is the call for all the IDs [1], the previous one only
 requests a single ID.

 <a href="https://invent.kde.org/kde/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/ContactsPlugin/ContactsPlugin.java#L196" target="_blank" rel="noreferrer" moz-do-not-send="true">https://invent.kde.org/kde/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/ContactsPlugin/ContactsPlugin.java#L196</a>

 On Sat, Oct 12, 2019 at 8:57 PM Albert Vaca Cintora
 <<a href="mailto:albertvaka@gmail.com" target="_blank" rel="noreferrer" moz-do-not-send="true">albertvaka@gmail.com</a>> wrote:
<blockquote class="gmail_quote" style="margin:0pt 0pt 1ex 0.8ex;border-left:1px solid #ad7fa8;padding-left:1ex">
 It looks like in getColumnsFromContactsForIDs [1] we are passing to
 many IDs. A solution probably would be we could request them in
 smaller batches.

 <a href="https://invent.kde.org/kde/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/ContactsPlugin/ContactsPlugin.java#L161" target="_blank" rel="noreferrer" moz-do-not-send="true">https://invent.kde.org/kde/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/ContactsPlugin/ContactsPlugin.java#L161</a>


 On Sat, Oct 12, 2019 at 7:19 PM Simon Redman <<a href="mailto:simon@ergotech.com" target="_blank" rel="noreferrer" moz-do-not-send="true">simon@ergotech.com</a>> wrote:
<blockquote class="gmail_quote" style="margin:0pt 0pt 1ex 0.8ex;border-left:1px solid #8ae234;padding-left:1ex">
 Hmm. I have no idea what is causing this (since it's below Android's
 "we're totally not using a sqlite database" layer)

 Is this reliably reproducible? (If so, how?)

 On 10/12/19 8:48 AM, Aleix Pol wrote:
<blockquote class="gmail_quote" style="margin:0pt 0pt 1ex 0.8ex;border-left:1px solid #fcaf3e;padding-left:1ex"> Hey Simon,
 I was looking at adb logs, I saw this error, maybe you can take a look.

 10-12 17:36:27.053 29958  2983 E KDE/Device:
 android.database.sqlite.SQLiteException: too many SQL variables (code
 1): , while compiling: SELECT lookup, contact_last_updated_timestamp
 FROM view_contacts WHERE ((1)) AND (lookup
 IN(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
 ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?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?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
 ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?))
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 android.content.ContentResolver.query(ContentResolver.java:754)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 android.content.ContentResolver.query(ContentResolver.java:704)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 android.content.ContentResolver.query(ContentResolver.java:662)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Helpers.ContactsHelper.getColumnsFromContactsForIDs(ContactsHelper.java:307)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Plugins.ContactsPlugin.ContactsPlugin.handleRequestAllUIDsTimestamps(ContactsPlugin.java:196)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Plugins.ContactsPlugin.ContactsPlugin.onPacketReceived(ContactsPlugin.java:253)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Device.onPacketReceived(Device.java:569)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Backends.BaseLink.packageReceived(BaseLink.java:84)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Backends.LanBackend.LanLink.receivedNetworkPacket(LanLink.java:255)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Backends.LanBackend.LanLink.lambda$reset$0$LanLink(LanLink.java:109)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 org.kde.kdeconnect.Backends.LanBackend.-$$Lambda$LanLink$TabvaCXA5qL_bcJDmIELWusNThw.run(Unknown
 Source:4)
 10-12 17:36:27.053 29958  2983 E KDE/Device:    at
 java.lang.Thread.run(Thread.java:764)
</blockquote>
</blockquote></blockquote></blockquote></pre>
                  </blockquote>
                </div>
              </div>
            </blockquote>
          </div>
        </blockquote>
        <br>
      </blockquote>
      <br>
    </blockquote>
    <br>
  </body>
</html>