Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-16668

Remove unnecessary conversions with queries

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 15.1.0.Dev04
    • None
    • None
    • None

      Modifying the EncoderCache to use the original key, we can avoid having to create new maps with the key conversion

      To remind me what I tested:

      diff --git a/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java b/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java
      index 2ae155f2876..e721734f969 100644
      --- a/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java
      +++ b/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java
      @@ -150,13 +150,12 @@ private CacheEntry<K, V> convertEntry(K newKey, V newValue, CacheEntry<K, V> ent
       
          private Map<K, CacheEntry<K, V>> decodeEntryMapForRead(Map<K, CacheEntry<K, V>> map) {
             Map<K, CacheEntry<K, V>> entryMap = new HashMap<>(map.size());
      -      map.values().forEach(v -> {
      -         K originalKey = v.getKey();
      -         K unwrappedKey = keyFromStorage(originalKey);
      diff --git a/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java b/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java
      index 2ae155f2876..e721734f969 100644
      --- a/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java
      +++ b/core/src/main/java/org/infinispan/cache/impl/EncoderCache.java
      @@ -150,13 +150,12 @@ private CacheEntry<K, V> convertEntry(K newKey, V newValue, CacheEntry<K, V> ent
       
          private Map<K, CacheEntry<K, V>> decodeEntryMapForRead(Map<K, CacheEntry<K, V>> map) {
             Map<K, CacheEntry<K, V>> entryMap = new HashMap<>(map.size());
      -      map.values().forEach(v -> {
      -         K originalKey = v.getKey();
      -         K unwrappedKey = keyFromStorage(originalKey);
      +      map.forEach((k, v) -> {
      +         K unwrappedKey = keyFromStorage(k);
                V originalValue = v.getValue();
                V unwrappedValue = valueFromStorage(originalValue);
                CacheEntry<K, V> entryToPut;
      -         if (unwrappedKey != originalKey || unwrappedValue != originalValue) {
      +         if (unwrappedKey != k || unwrappedValue != originalValue) {
                   entryToPut = convertEntry(unwrappedKey, unwrappedValue, v);
                } else {
                   entryToPut = v;
      diff --git a/query/src/main/java/org/infinispan/query/clustered/DistributedEntryIterator.java b/query/src/main/java/org/infinispan/query/clustered/DistributedEntryIterator.java
      index 4a886cf8342..2bbbe71d0b1 100644
      --- a/query/src/main/java/org/infinispan/query/clustered/DistributedEntryIterator.java
      +++ b/query/src/main/java/org/infinispan/query/clustered/DistributedEntryIterator.java
      @@ -48,12 +48,10 @@ protected void getAllAndStore(List<KeyAndScore> keysAndScores) {
             Set<Object> keySet = keysAndScores.stream()
                   .map(keyAndScore -> keyAndScore.key)
                   .collect(Collectors.toSet());
      -      Map<?, CacheEntry<Object, Object>> convertedMap =
      -            queryKeyConverter.convertEntries(cache.getAllCacheEntries(keySet));
      -      keysAndScores.forEach(bla -> bla.covertedKey = queryKeyConverter.convert(bla.key));
      +      Map<?, CacheEntry<Object, Object>> convertedMap = cache.getAllCacheEntries(keySet);
             keysAndScores.stream()
                   .map(keyAndScore -> {
      -               CacheEntry<Object, Object> cacheEntry = convertedMap.get(keyAndScore.covertedKey);
      +               CacheEntry<Object, Object> cacheEntry = convertedMap.get(keyAndScore.key);
                      return decorate(keyAndScore.key,
                            cacheEntry.getValue(), keyAndScore.score, cacheEntry.getMetadata());
                   })
      diff --git a/query/src/main/java/org/infinispan/query/impl/MetadataEntityLoader.java b/query/src/main/java/org/infinispan/query/impl/MetadataEntityLoader.java
      index 2717748956d..e8954923f7f 100644
      --- a/query/src/main/java/org/infinispan/query/impl/MetadataEntityLoader.java
      +++ b/query/src/main/java/org/infinispan/query/impl/MetadataEntityLoader.java
      @@ -39,16 +39,15 @@ public List<EntityLoaded<E>> loadBlocking(List<?> identifiers, Deadline deadline
       
             // getAll instead of multiple gets to get all the results in the same call
             Map<?, ? extends CacheEntry<?, E>> entries = cache.getAllCacheEntries(keys);
      -      Map<?, ? extends CacheEntry<?, E>> values = queryKeyConverter.convertEntries(entries);
       
             if (queryStatistics.isEnabled()) queryStatistics.entityLoaded(System.nanoTime() - start);
       
             ArrayList<EntityLoaded<E>> result = new ArrayList<>(keys.size());
      -      for (Object key : keys) {
      +      for (Object key : identifiers) {
                // if the entity was present at indexing time and
                // it is not present anymore now at searching time,
                // we will add a null here
      -         CacheEntry<?, E> cacheEntry = values.get(key);
      +         CacheEntry<?, E> cacheEntry = entries.get(key);
                if (cacheEntry != null) {
                   result.add(new EntityLoaded<>(cacheEntry.getValue(), cacheEntry.getMetadata()));
                } else {
      

              pruivo@redhat.com Pedro Ruivo
              pruivo@redhat.com Pedro Ruivo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: