From d9361204e6d61f7defb3fb350d3751fd2c21956a Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 17 Jun 2021 13:45:19 +0300 Subject: [PATCH] Fix IndexedRelationsSearcher to invalid memory-based cache upon remove gitlab #725 (cherry picked from commit 89eb86c3ca993d038dd623fe0963f3bc29394b28) --- .../db/indexing/IndexedRelationsSearcher.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcher.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcher.java index a535183f2..c2d0a3d03 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcher.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcher.java @@ -71,7 +71,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase { void insertIndex(IProgressMonitor monitor, GenericRelation r, int boundLength, Collection documentsData) throws CorruptIndexException, IOException, DatabaseException { - Collection keyValues = new ArrayList(); + Collection 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 keyValues) throws DatabaseException,CorruptIndexException, IOException { - Collection documentsData = new ArrayList(); + Collection documentsData = new ArrayList<>(); Pair[] fields = r.getFields(); @@ -142,7 +148,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase { List> results = super.doSearch(monitor, processor, search, maxResultCount); if(cache == null) { - cache = new HashMap>>(); + cache = new HashMap<>(); mem.persistentCache.put(key, cache); } @@ -170,7 +176,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase { List results = super.doSearchResources(monitor, processor, search, maxResultCount); if(cache == null) { - cache = new HashMap>(); + cache = new HashMap<>(); mem.persistentCacheResources.put(key, cache); } @@ -198,7 +204,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase { List> persistent = persistentCachedSearch(monitor, processor, search, maxResultCount); List> cached = cache.doSearch(monitor, processor, search, maxResultCount); - ArrayList> result = new ArrayList>(); + ArrayList> result = new ArrayList<>(); for(Map m : persistent) { Resource r = (Resource)m.get("Resource"); @@ -218,7 +224,7 @@ public class IndexedRelationsSearcher extends IndexedRelationsSearcherBase { List persistent = persistentCachedSearchResources(monitor, processor, search, maxResultCount); List cached = cache.doSearchResources(monitor, processor, search, maxResultCount); - ArrayList result = new ArrayList(); + ArrayList 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 replaceKeys = new ArrayList(); - ArrayList replaceValues = new ArrayList(); - ArrayList removeKeys = new ArrayList(); + ArrayList replaceKeys = new ArrayList<>(); + ArrayList replaceValues = new ArrayList<>(); + ArrayList removeKeys = new ArrayList<>(); for(Object[] o : os) { Long parent = (Long)o[0]; Long key = (Long)o[1]; -- 2.47.1