]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix IndexedRelationsSearcher to invalid memory-based cache upon remove
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 17 Jun 2021 10:45:19 +0000 (13:45 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 18 Jun 2021 15:57:32 +0000 (15:57 +0000)
gitlab #725

(cherry picked from commit 89eb86c3ca993d038dd623fe0963f3bc29394b28)

bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcher.java

index a535183f2cd7ce0289c82b1638264d4331ef95b8..c2d0a3d0348b9050798d90a7e3f44c73d5ac1cda 100644 (file)
@@ -71,7 +71,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase {
     void insertIndex(IProgressMonitor monitor, GenericRelation r, int boundLength, Collection<Object[]> documentsData)
             throws CorruptIndexException, IOException, DatabaseException {
 
-        Collection<Object> keyValues = new ArrayList<Object>();
+        Collection<Object> keyValues = new ArrayList<>();
         for(Object[] data : documentsData) {
             keyValues.add(data[1]);
         }
@@ -80,11 +80,17 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase {
         //cache.commit();
         
     }
-    
+
+    @Override
+    void removeIndex(IProgressMonitor monitor) throws DatabaseException, CorruptIndexException, IOException {
+        super.removeIndex(monitor);
+        cache.removeIndex(monitor);
+    }
+
     @Override
     void removeIndex(IProgressMonitor monitor, GenericRelation r, RequestProcessor processor, String key, Collection<Object> keyValues) throws DatabaseException,CorruptIndexException, IOException {
         
-        Collection<Object[]> documentsData = new ArrayList<Object[]>();
+        Collection<Object[]> documentsData = new ArrayList<>();
 
         Pair<String,String>[] fields = r.getFields(); 
 
@@ -142,7 +148,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase {
 
         List<Map<String, Object>> results = super.doSearch(monitor, processor, search, maxResultCount);
         if(cache == null) {
-            cache = new HashMap<String,List<Map<String,Object>>>();
+            cache = new HashMap<>();
             mem.persistentCache.put(key, cache);
         }
 
@@ -170,7 +176,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase {
 
         List<Resource> results = super.doSearchResources(monitor, processor, search, maxResultCount);
         if(cache == null) {
-            cache = new HashMap<String,List<Resource>>();
+            cache = new HashMap<>();
             mem.persistentCacheResources.put(key, cache);
         }
 
@@ -198,7 +204,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase {
         List<Map<String,Object>> persistent = persistentCachedSearch(monitor, processor, search, maxResultCount);
         List<Map<String,Object>> cached = cache.doSearch(monitor, processor, search, maxResultCount);
 
-        ArrayList<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
+        ArrayList<Map<String,Object>> result = new ArrayList<>();
 
         for(Map<String,Object> m : persistent) {
             Resource r = (Resource)m.get("Resource");
@@ -218,7 +224,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase {
         List<Resource> persistent = persistentCachedSearchResources(monitor, processor, search, maxResultCount);
         List<Resource> cached = cache.doSearchResources(monitor, processor, search, maxResultCount);
 
-        ArrayList<Resource> result = new ArrayList<Resource>();
+        ArrayList<Resource> result = new ArrayList<>();
         for(Resource r : persistent) {
             if(!cache.changed.contains(r.getResourceId())) {
                 result.add(r);
@@ -245,9 +251,9 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase {
        
        if(!os.isEmpty()) {
        
-               ArrayList<Object> replaceKeys = new ArrayList<Object>();
-               ArrayList<Object[]> replaceValues = new ArrayList<Object[]>();
-               ArrayList<Object> removeKeys = new ArrayList<Object>();
+               ArrayList<Object> replaceKeys = new ArrayList<>();
+               ArrayList<Object[]> replaceValues = new ArrayList<>();
+               ArrayList<Object> removeKeys = new ArrayList<>();
                for(Object[] o : os) {
                    Long parent = (Long)o[0];
                    Long key = (Long)o[1];