Uploaded image for project: 'Nuxeo Java Client'
  1. Nuxeo Java Client
  2. JAVACLIENT-231

Fix caching of search queries

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.13.0
    • Fix Version/s: 3.14.0
    • Component/s: Core
    • Backlog priority:
      550
    • Sprint:
      nxplatform #73
    • Story Points:
      3

      Description

      When executing several times the same NXQL query with client.repository().query(), the cached result is not returned, new entries in the cache are created at each execution.

      The issue is located in the creation of the cache key, it is always unique, even when the NXQL query has already been sent.

      Here is the diff in a unit test class showing the issue:

      diff --git a/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java b/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java
      index f7f4f2a..b2bfb08 100644
      --- a/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java
      +++ b/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java
      @@ -271,6 +271,19 @@ public class ITRepository extends AbstractITBase {
               document = client.repository().fetchDocumentByPath("/folder_1/note_0");
               assertEquals("note updated again", document.getPropertyValue("dc:title"));
               assertEquals(1, client.getNuxeoCache().size());
      +        
      +        // Refresh the cache and check the update has been recovered.
      +        client.getNuxeoCache().invalidateAll();
      +        String query = "SELECT * FROM Document WHERE ecm:isVersion=0 AND isProxy=0 AND isTrashed=0 and dc:title=? AND description=?";
      +        client.repository().query(query, "1000", "0", null, "dc:title", "ASC", "Tile-1", "Desc-1");
      +        assertEquals(1, client.getNuxeoCache().size());
      +        client.repository().query(query, "1000", "0", null, "dc:title", "ASC", "Tile-1", "Desc-1");
      +        assertEquals(1, client.getNuxeoCache().size());
      +        client.repository().query(query, "1000", "0", null, "dc:title", "ASC", "Tile-1", "Desc-2");
      +        assertEquals(2, client.getNuxeoCache().size());
      +        query = "SELECT * FROM Document WHERE ecm:isVersion=0 AND isProxy=0 AND isTrashed=0 and dc:title=?";
      +        client.repository().query(query, "1000", "0", null, "dc:title", "ASC", "Tile-1");
      +        assertEquals(3, client.getNuxeoCache().size());
           }
       
           @Test
      

      Here is a fix that seems to work:

      diff --git a/nuxeo-java-client/src/main/java/org/nuxeo/client/NuxeoClient.java b/nuxeo-java-client/src/main/java/org/nuxeo/client/NuxeoClient.java
      index 376c081..539b633 100644
      --- a/nuxeo-java-client/src/main/java/org/nuxeo/client/NuxeoClient.java
      +++ b/nuxeo-java-client/src/main/java/org/nuxeo/client/NuxeoClient.java
      @@ -438,7 +438,7 @@ public class NuxeoClient extends AbstractBase<NuxeoClient> {
               } catch (NoSuchAlgorithmException e) {
                   return null;
               }
      -        digest.update((originalRequest.toString() + originalRequest.headers().toString()).getBytes());
      +        digest.update((originalRequest.url().toString() + originalRequest.headers().toString()).getBytes());
               byte[] messageDigest = digest.digest();
               StringBuilder hexString = new StringBuilder();
               for (byte msg : messageDigest) {
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: