You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by js...@apache.org on 2023/03/09 18:15:32 UTC

[unomi] 01/01: UNOMI-700 : remove useless refresh

This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a commit to branch UNOMI-700-remove-useless-refresh-1_X
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 04f5295b6d67e4ef3c3180a2053eab57387b2de7
Author: jsinovassin <js...@jahia.com>
AuthorDate: Thu Mar 9 19:15:21 2023 +0100

    UNOMI-700 : remove useless refresh
---
 .../apache/unomi/services/UserListServiceImpl.java |  2 +-
 .../test/java/org/apache/unomi/itests/BaseIT.java  |  8 +++--
 .../unomi/itests/ConditionESQueryBuilderIT.java    |  3 +-
 .../org/apache/unomi/itests/ContextServletIT.java  | 39 +++++++++-------------
 .../unomi/itests/CopyPropertiesActionIT.java       |  4 +--
 .../org/apache/unomi/itests/EventServiceIT.java    |  9 +++--
 .../unomi/itests/GroovyActionsServiceIT.java       |  7 ++--
 .../apache/unomi/itests/IncrementPropertyIT.java   |  6 ++--
 .../unomi/itests/PropertiesUpdateActionIT.java     | 22 ++++++------
 .../org/apache/unomi/itests/RuleServiceIT.java     |  8 ++---
 .../java/org/apache/unomi/itests/SegmentIT.java    | 18 +++++-----
 .../impl/definitions/DefinitionsServiceImpl.java   |  3 +-
 .../services/impl/goals/GoalsServiceImpl.java      |  2 +-
 .../services/impl/profiles/ProfileServiceImpl.java |  2 +-
 .../services/impl/rules/RulesServiceImpl.java      |  4 +--
 15 files changed, 69 insertions(+), 68 deletions(-)

diff --git a/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java b/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java
index 37ca72e04..af652b12f 100644
--- a/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java
+++ b/extensions/lists-extension/services/src/main/java/org/apache/unomi/services/UserListServiceImpl.java
@@ -57,7 +57,7 @@ public class UserListServiceImpl implements UserListService {
 
     public PartialList<Metadata> getListMetadatas(Query query) {
         if(query.isForceRefresh()){
-            persistenceService.refresh();
+            persistenceService.refreshIndex(UserList.class, null);
         }
         definitionsService.resolveConditionType(query.getCondition());
         PartialList<UserList> userLists = persistenceService.query(query.getCondition(), query.getSortby(), UserList.class, query.getOffset(), query.getLimit());
diff --git a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
index 27588c61a..c8420a324 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
@@ -114,11 +114,13 @@ public abstract class BaseIT {
         for (Class<? extends Item> aClass : classes) {
             persistenceService.removeByQuery(condition, aClass);
         }
-        refreshPersistence();
+        refreshPersistence(classes);
     }
 
-    protected void refreshPersistence() throws InterruptedException {
-        persistenceService.refresh();
+    protected void refreshPersistence(final Class<? extends Item>... classes) throws InterruptedException {
+        for (Class<? extends Item> aClass : classes) {
+            persistenceService.refreshIndex(aClass, null);
+        }
         Thread.sleep(1000);
     }
 
diff --git a/itests/src/test/java/org/apache/unomi/itests/ConditionESQueryBuilderIT.java b/itests/src/test/java/org/apache/unomi/itests/ConditionESQueryBuilderIT.java
index 3e4333c96..3f19b7ab2 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ConditionESQueryBuilderIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ConditionESQueryBuilderIT.java
@@ -18,6 +18,7 @@
 package org.apache.unomi.itests;
 
 import org.apache.unomi.api.Item;
+import org.apache.unomi.api.Profile;
 import org.apache.unomi.api.conditions.Condition;
 import org.junit.After;
 import org.junit.Before;
@@ -48,7 +49,7 @@ public class ConditionESQueryBuilderIT extends ConditionEvaluatorIT {
     public void setUp() {
         super.setUp();
         persistenceService.save(item);
-        persistenceService.refresh();
+        persistenceService.refreshIndex(Profile.class, null);
     }
 
     @After
diff --git a/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java b/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
index 9d0fa26bc..57da03232 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ContextServletIT.java
@@ -113,7 +113,7 @@ public class ContextServletIT extends BaseIT {
 		profile.setProperty("firstName", TEST_PROFILE_FIRST_NAME);
 		profileService.save(profile);
 
-		refreshPersistence();
+		refreshPersistence(Profile.class);
 	}
 
 	@After
@@ -139,7 +139,8 @@ public class ContextServletIT extends BaseIT {
 		Event event = new Event(eventId, eventTypeOriginal, session, profile, scope, null, null, new Date());
 		profileService.save(profile);
 		this.eventService.send(event);
-		refreshPersistence();
+		refreshPersistence(Profile.class);
+		persistenceService.refreshIndex(Event.class, new Date());
 		Thread.sleep(2000);
 		event.setEventType(eventTypeUpdated); //change the event so we can see the update effect
 
@@ -151,7 +152,7 @@ public class ContextServletIT extends BaseIT {
 		request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY);
 		request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
 		TestUtils.executeContextJSONRequest(request, sessionId);
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 		Thread.sleep(2000); //Making sure event is updated in DB
 
 		//Assert
@@ -174,7 +175,8 @@ public class ContextServletIT extends BaseIT {
 		Event event = new Event(eventId, eventTypeOriginal, session, profile, scope, null, null, new Date());
 		profileService.save(profile);
 		this.eventService.send(event);
-		refreshPersistence();
+		refreshPersistence(Profile.class);
+		persistenceService.refreshIndex(Event.class, new Date());
 		Thread.sleep(2000);
 		event.setEventType(eventTypeUpdated); //change the event so we can see the update effect
 
@@ -185,7 +187,7 @@ public class ContextServletIT extends BaseIT {
 		HttpPost request = new HttpPost(URL + CONTEXT_URL);
 		request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
 		TestUtils.executeContextJSONRequest(request, sessionId);
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 		Thread.sleep(2000); //Making sure event is updated in DB
 
 		//Assert
@@ -206,7 +208,7 @@ public class ContextServletIT extends BaseIT {
 		Session session = new Session(sessionId, profile, new Date(), scope);
 		Event event = new Event(eventId, eventTypeOriginal, session, profile, scope, null, null, new Date());
 		this.eventService.send(event);
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 		Thread.sleep(2000);
 		event.setEventType(eventTypeUpdated); //change the event so we can see the update effect
 
@@ -217,7 +219,7 @@ public class ContextServletIT extends BaseIT {
 		HttpPost request = new HttpPost(URL + CONTEXT_URL);
 		request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
 		TestUtils.executeContextJSONRequest(request, sessionId);
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 		Thread.sleep(2000); //Making sure event is updated in DB
 
 		//Assert
@@ -243,15 +245,13 @@ public class ContextServletIT extends BaseIT {
 		HttpPost request = new HttpPost(URL + CONTEXT_URL);
 		request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
 		String cookieHeaderValue = TestUtils.executeContextJSONRequest(request, sessionId).getCookieHeaderValue();
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 		Thread.sleep(1000); //Making sure DB is updated
 
 		//Add the context-profile-id cookie to the second event
 		request.addHeader("Cookie", cookieHeaderValue);
 		ContextResponse response = (TestUtils.executeContextJSONRequest(request, sessionId)).getContextResponse(); //second event
 
-		refreshPersistence();
-
 		//Assert
 		assertEquals(1, response.getProfileSegments().size());
 		assertThat(response.getProfileSegments(),hasItem(SEGMENT_ID));
@@ -278,12 +278,12 @@ public class ContextServletIT extends BaseIT {
 		request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
 		//The first event is with a default timestamp (now)
 		String cookieHeaderValue = TestUtils.executeContextJSONRequest(request, sessionId).getCookieHeaderValue();
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 		//The second event is with a customized timestamp
 		request.setURI(URI.create(customTimestampURI));
 		request.addHeader("Cookie", cookieHeaderValue);
 		ContextResponse response = (TestUtils.executeContextJSONRequest(request, sessionId)).getContextResponse(); //second event
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 
 		//Assert
 		assertEquals(0,response.getProfileSegments().size());
@@ -310,12 +310,12 @@ public class ContextServletIT extends BaseIT {
 		request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
 		//The first event is with a default timestamp (now)
 		String cookieHeaderValue = TestUtils.executeContextJSONRequest(request, sessionId).getCookieHeaderValue();
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date());
 		//The second event is with a customized timestamp
 		request.setURI(URI.create(customTimestampURI));
 		request.addHeader("Cookie", cookieHeaderValue);
 		ContextResponse response = (TestUtils.executeContextJSONRequest(request, sessionId)).getContextResponse(); //second event
-		refreshPersistence();
+		persistenceService.refreshIndex(Event.class, new Date(futureTimestamp));
 
 		//Assert
 		assertEquals(0,response.getProfileSegments().size());
@@ -340,7 +340,7 @@ public class ContextServletIT extends BaseIT {
 		request.addHeader(THIRD_PARTY_HEADER_NAME, UNOMI_KEY);
 		request.setEntity(new StringEntity(objectMapper.writeValueAsString(contextRequest), ContentType.create("application/json")));
 		TestUtils.executeContextJSONRequest(request);
-		refreshPersistence();
+		refreshPersistence(Profile.class);
 		Thread.sleep(2000); //Making sure event is updated in DB
 
 		//Assert
@@ -363,7 +363,6 @@ public class ContextServletIT extends BaseIT {
 		HttpPost request = new HttpPost(URL + CONTEXT_URL);
 		request.setEntity(new StringEntity(getValidatedBundleJSON("security/ognl-payload-1.json", parameters), ContentType.create("application/json")));
 		TestUtils.executeContextJSONRequest(request);
-		refreshPersistence();
 		Thread.sleep(2000); //Making sure event is updated in DB
 
 		assertFalse("Vulnerability successfully executed ! File created at " + vulnFileCanonicalPath, vulnFile.exists());
@@ -385,7 +384,6 @@ public class ContextServletIT extends BaseIT {
 		HttpPost request = new HttpPost(URL + CONTEXT_URL);
 		request.setEntity(new StringEntity(getValidatedBundleJSON("security/mvel-payload-1.json", parameters), ContentType.create("application/json")));
 		TestUtils.executeContextJSONRequest(request);
-		refreshPersistence();
 		Thread.sleep(2000); //Making sure event is updated in DB
 
 		assertFalse("Vulnerability successfully executed ! File created at " + vulnFileCanonicalPath, vulnFile.exists());
@@ -400,9 +398,6 @@ public class ContextServletIT extends BaseIT {
 		request.setEntity(new StringEntity(getValidatedBundleJSON("personalization.json", parameters), ContentType.create("application/json")));
 		TestUtils.RequestResponse response = TestUtils.executeContextJSONRequest(request);
 		assertEquals("Invalid response code", 200, response.getStatusCode());
-		refreshPersistence();
-		Thread.sleep(2000); //Making sure event is updated in DB
-
 	}
 
     @Test
@@ -412,7 +407,7 @@ public class ContextServletIT extends BaseIT {
         String scoringSource = getValidatedBundleJSON("score1.json", parameters);
         Scoring scoring = CustomObjectMapper.getObjectMapper().readValue(scoringSource, Scoring.class);
         segmentService.setScoringDefinition(scoring);
-        refreshPersistence();
+        refreshPersistence(Segment.class);
 
         // first let's make sure everything works without the requireScoring parameter
         parameters = new HashMap<>();
@@ -420,7 +415,6 @@ public class ContextServletIT extends BaseIT {
         request.setEntity(new StringEntity(getValidatedBundleJSON("withoutRequireScores.json", parameters), ContentType.create("application/json")));
         TestUtils.RequestResponse response = TestUtils.executeContextJSONRequest(request);
         assertEquals("Invalid response code", 200, response.getStatusCode());
-        refreshPersistence();
         Thread.sleep(2000); //Making sure event is updated in DB
 
         assertNotNull("Context response should not be null", response.getContextResponse());
@@ -433,7 +427,6 @@ public class ContextServletIT extends BaseIT {
         request.setEntity(new StringEntity(getValidatedBundleJSON("withRequireScores.json", parameters), ContentType.create("application/json")));
         response = TestUtils.executeContextJSONRequest(request);
         assertEquals("Invalid response code", 200, response.getStatusCode());
-        refreshPersistence();
         Thread.sleep(2000); //Making sure event is updated in DB
 
         assertNotNull("Context response should not be null", response.getContextResponse());
diff --git a/itests/src/test/java/org/apache/unomi/itests/CopyPropertiesActionIT.java b/itests/src/test/java/org/apache/unomi/itests/CopyPropertiesActionIT.java
index c51455080..322746ce2 100644
--- a/itests/src/test/java/org/apache/unomi/itests/CopyPropertiesActionIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/CopyPropertiesActionIT.java
@@ -90,7 +90,7 @@ public class CopyPropertiesActionIT extends BaseIT {
         profileService.save(profileTarget);
         LOGGER.info("Profile saved with ID [{}].", profileTarget.getItemId());
 
-        refreshPersistence();
+        refreshPersistence(Profile.class);
     }
 
     @After
@@ -99,7 +99,7 @@ public class CopyPropertiesActionIT extends BaseIT {
         profileService.delete(EMPTY_PROFILE, false);
         profileService.deletePropertyType(ARRAY_PARAM_NAME);
         profileService.deletePropertyType(SINGLE_PARAM_NAME);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
     }
 
     private void initializePropertyType() {
diff --git a/itests/src/test/java/org/apache/unomi/itests/EventServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/EventServiceIT.java
index 530baa86f..936134264 100644
--- a/itests/src/test/java/org/apache/unomi/itests/EventServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/EventServiceIT.java
@@ -78,7 +78,8 @@ public class EventServiceIT extends BaseIT {
         Event event = new Event(eventId, eventType, null, profile, null, null, null, new Date());
         profileService.save(profile);
         eventService.send(event);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
+        persistenceService.refreshIndex(Event.class, new Date());
         Thread.sleep(2000);
         boolean exist = eventService.hasEventAlreadyBeenRaised(event);
         Assert.assertTrue(exist);
@@ -96,7 +97,8 @@ public class EventServiceIT extends BaseIT {
 
         profileService.save(profile);
         eventService.send(event);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
+        persistenceService.refreshIndex(Event.class, new Date());
         Thread.sleep(2000);
 
         Condition eventTypeCondition = new Condition(definitionsService.getConditionType("eventTypeCondition"));
@@ -130,7 +132,8 @@ public class EventServiceIT extends BaseIT {
 
         profileService.save(profile);
         eventService.send(event);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
+        persistenceService.refreshIndex(Event.class, timestamp);
         Thread.sleep(2000);
 
         Condition eventTypeCondition = new Condition(definitionsService.getConditionType("eventTypeCondition"));
diff --git a/itests/src/test/java/org/apache/unomi/itests/GroovyActionsServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/GroovyActionsServiceIT.java
index d34734a1a..a0d42cd3e 100644
--- a/itests/src/test/java/org/apache/unomi/itests/GroovyActionsServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/GroovyActionsServiceIT.java
@@ -27,6 +27,7 @@ import org.apache.unomi.api.services.DefinitionsService;
 import org.apache.unomi.api.services.EventService;
 import org.apache.unomi.api.services.ProfileService;
 import org.apache.unomi.api.services.RulesService;
+import org.apache.unomi.groovy.actions.GroovyAction;
 import org.apache.unomi.groovy.actions.services.GroovyActionsService;
 import org.apache.unomi.persistence.spi.CustomObjectMapper;
 import org.junit.After;
@@ -85,13 +86,13 @@ public class GroovyActionsServiceIT extends BaseIT {
         profile.setProperty("firstname", "Alexandre");
         profile.setProperty("address", "Address");
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
     }
 
     @After
     public void cleanUp() throws InterruptedException {
         profileService.delete(PROFILE_ID, false);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
     }
 
     private String loadGroovyAction(String pathname) throws IOException {
@@ -161,7 +162,7 @@ public class GroovyActionsServiceIT extends BaseIT {
         Assert.assertNotNull(groovyCodeSource);
 
         groovyActionsService.remove(UPDATE_ADDRESS_ACTION);
-        refreshPersistence();
+        refreshPersistence(GroovyAction.class);
 
         Thread.sleep(2000);
         groovyCodeSource = groovyActionsService.getGroovyCodeSource(UPDATE_ADDRESS_ACTION);
diff --git a/itests/src/test/java/org/apache/unomi/itests/IncrementPropertyIT.java b/itests/src/test/java/org/apache/unomi/itests/IncrementPropertyIT.java
index 3b75ce776..af983dabf 100644
--- a/itests/src/test/java/org/apache/unomi/itests/IncrementPropertyIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/IncrementPropertyIT.java
@@ -81,7 +81,7 @@ public class IncrementPropertyIT extends BaseIT {
 
         if (eventCode == EventService.PROFILE_UPDATED) {
             Profile updatedProfile = profileService.save(event.getProfile());
-            refreshPersistence();
+            refreshPersistence(Profile.class);
 
             int value = ((Map<String, Integer>) updatedProfile.getProperty("pageView")).get("acme-space");
             Assert.assertEquals(1, value, 0.0);
@@ -401,7 +401,7 @@ public class IncrementPropertyIT extends BaseIT {
         event.setPersistent(false);
 
         int eventCode = eventService.send(event);
-        refreshPersistence();
+        persistenceService.refreshIndex(Event.class, new Date());
 
         return eventCode;
     }
@@ -427,7 +427,7 @@ public class IncrementPropertyIT extends BaseIT {
         Profile profile = new Profile(UUID.randomUUID().toString());
 
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
 
         return profile;
     }
diff --git a/itests/src/test/java/org/apache/unomi/itests/PropertiesUpdateActionIT.java b/itests/src/test/java/org/apache/unomi/itests/PropertiesUpdateActionIT.java
index f13007dce..20c650831 100644
--- a/itests/src/test/java/org/apache/unomi/itests/PropertiesUpdateActionIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/PropertiesUpdateActionIT.java
@@ -79,7 +79,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         profileService.save(profileTarget);
         LOGGER.info("Profile saved with ID [{}].", profileTarget.getItemId());
 
-        refreshPersistence();
+        refreshPersistence(Profile.class);
     }
 
     @Test
@@ -145,7 +145,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         updateProperties.setProperty(UpdatePropertiesAction.TARGET_TYPE_KEY, "profile");
         eventService.send(updateProperties);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
 
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals("Props_to_add should set the prop if it's missing", "New property 1", profile.getProperty("prop1"));
@@ -171,7 +171,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         updateProperties.setProperty(UpdatePropertiesAction.TARGET_TYPE_KEY, "profile");
         eventService.send(updateProperties);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
 
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals("New property 1", profile.getProperty("prop1"));
@@ -190,7 +190,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         updateProperties.setProperty(UpdatePropertiesAction.TARGET_TYPE_KEY, "profile");
         eventService.send(updateProperties);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
 
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals(2, ((List<String>) profile.getProperty("prop1")).size());
@@ -217,7 +217,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         updateProperties.setProperty(UpdatePropertiesAction.TARGET_TYPE_KEY, "profile");
         eventService.send(updateProperties);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
 
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals("New property 1", profile.getProperty("prop1"));
@@ -237,7 +237,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
 
         eventService.send(updateProperties);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
 
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertNull(profile.getProperty("prop1bis"));
@@ -260,7 +260,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         sessionReassigned.setPersistent(false);
         eventService.send(sessionReassigned);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals("lastVisit should be updated", eventTimeStamp1, profile.getProperty("lastVisit"));
         Assert.assertEquals("firstVisit should be updated", eventTimeStamp1, profile.getProperty("firstVisit"));
@@ -276,7 +276,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         sessionReassigned.setPersistent(false);
         eventService.send(sessionReassigned);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals("lastVisit should not be updated", eventTimeStamp1, profile.getProperty("lastVisit"));
         Assert.assertEquals("firstVisit should be updated", eventTimeStamp2, profile.getProperty("firstVisit"));
@@ -292,7 +292,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         sessionReassigned.setPersistent(false);
         eventService.send(sessionReassigned);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals("lastVisit should be updated", eventTimeStamp3, profile.getProperty("lastVisit"));
         Assert.assertEquals("firstVisit should not be updated", eventTimeStamp2, profile.getProperty("firstVisit"));
@@ -308,7 +308,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
         sessionReassigned.setPersistent(false);
         eventService.send(sessionReassigned);
         profileService.save(profile);
-        refreshPersistence();
+        refreshPersistence(Profile.class);
         profile = profileService.load(PROFILE_TEST_ID);
         Assert.assertEquals("lastVisit should not be updated", eventTimeStamp3, profile.getProperty("lastVisit"));
         Assert.assertEquals("firstVisit should not be updated", eventTimeStamp2, profile.getProperty("firstVisit"));
@@ -333,7 +333,7 @@ public class PropertiesUpdateActionIT extends BaseIT {
             Thread.sleep(4000); // small sleep to create time dif between eventTimeStamp and current system date
             eventService.send(sessionReassigned);
             profileService.save(profile);
-            refreshPersistence();
+            refreshPersistence(Profile.class);
             profile = profileService.load(PROFILE_TEST_ID);
             Assert.assertEquals("currentEventTimeStamp should be the exact date of the event timestamp", eventTimeStamp1, profile.getProperty("currentEventTimeStamp"));
             Assert.assertNotEquals("currentDate should be the current system date", eventTimeStamp1, profile.getProperty("currentDate"));
diff --git a/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java
index d016f1e1b..726f43798 100644
--- a/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/RuleServiceIT.java
@@ -82,7 +82,7 @@ public class RuleServiceIT extends BaseIT {
         assertNull("Expected rule condition to be null", nullRule.getCondition());
         assertEquals("Invalid rule name", TEST_RULE_ID + "_name", nullRule.getMetadata().getName());
         rulesService.removeRule(TEST_RULE_ID);
-        refreshPersistence();
+        refreshPersistence(Rule.class);
         rulesService.refreshRules();
     }
 
@@ -107,7 +107,7 @@ public class RuleServiceIT extends BaseIT {
             String ruleID = ruleIDBase + "_" + i;
             rulesService.removeRule(ruleID);
         }
-        refreshPersistence();
+        refreshPersistence(Rule.class);
         rulesService.refreshRules();
     }
 
@@ -152,7 +152,7 @@ public class RuleServiceIT extends BaseIT {
         rulesService.removeRule(simpleEventTypeRule.getItemId());
         rulesService.removeRule(complexEventTypeRule.getItemId());
         rulesService.removeRule(noEventTypeRule.getItemId());
-        refreshPersistence();
+        refreshPersistence(Rule.class);
         rulesService.refreshRules();
     }
 
@@ -224,7 +224,7 @@ public class RuleServiceIT extends BaseIT {
             ConditionType conditionType = CustomObjectMapper.getObjectMapper().readValue(
                     new File("data/tmp/testClickEventCondition.json").toURI().toURL(), ConditionType.class);
             definitionsService.setConditionType(conditionType);
-            refreshPersistence();
+            refreshPersistence(Rule.class);
             rulesService.refreshRules();
             // Test tracked parameter
             // Add rule that has a trackParameter condition that matches
diff --git a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
index a140835c2..29e022025 100644
--- a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
@@ -544,18 +544,18 @@ public class SegmentIT extends BaseIT {
         scoringElements.add(scoringElement);
         scoring.setElements(scoringElements);
         segmentService.setScoringDefinition(scoring);
-        refreshPersistence();
+        refreshPersistence(Segment.class);
 
         // Send 2 events that match the scoring plan.
         profile = profileService.load("test_profile_id");
         Event testEvent = new Event("test-event-type", null, profile, null, null, profile, timestampEventInRange);
         testEvent.setPersistent(true);
         eventService.send(testEvent);
-        refreshPersistence();
+        persistenceService.refreshIndex(Event.class, timestampEventInRange);
         // 2nd event
         testEvent = new Event("test-event-type", null, testEvent.getProfile(), null, null, testEvent.getProfile(), timestampEventInRange);
         eventService.send(testEvent);
-        refreshPersistence();
+        persistenceService.refreshIndex(Event.class, timestampEventInRange);
 
         // insure the profile is engaged;
         try {
@@ -565,7 +565,7 @@ public class SegmentIT extends BaseIT {
             Assert.fail("Unable to read past event because " + e.getMessage());
         }
         profileService.save(testEvent.getProfile());
-        refreshPersistence();
+        refreshPersistence(Profile.class);
         // recalculate event conditions
         segmentService.recalculatePastEventConditions();
         // insure the profile is still engaged after recalculate;
@@ -595,10 +595,10 @@ public class SegmentIT extends BaseIT {
             Assert.fail("Unable to read past event because " + e.getMessage());
         }
         profileService.save(testEvent.getProfile());
-        refreshPersistence();
+        refreshPersistence(Profile.class);
         // now recalculate the past event conditions
         segmentService.recalculatePastEventConditions();
-        persistenceService.refreshIndex(Profile.class, null);
+        refreshPersistence(Profile.class);
         // As 3 events have match, the profile should not be part of the scoring plan.
         keepTrying("Profile should not be part of the scoring anymore",
                 () -> profileService.load("test_profile_id"),
@@ -638,7 +638,7 @@ public class SegmentIT extends BaseIT {
         scoringElements.add(scoringElement);
         scoring.setElements(scoringElements);
         segmentService.setScoringDefinition(scoring);
-        refreshPersistence();
+        refreshPersistence(Segment.class);
         // Check linkedItems
         List<Rule> rules = persistenceService.getAllItems(Rule.class);
         Rule scoringRule = rules.stream().filter(rule -> rule.getItemId().equals(pastEventCondition.getParameter("generatedPropertyKey"))).findFirst().get();
@@ -646,7 +646,7 @@ public class SegmentIT extends BaseIT {
 
         // save the scoring once again
         segmentService.setScoringDefinition(scoring);
-        refreshPersistence();
+        refreshPersistence(Segment.class);
         // Check linkedItems
         rules = persistenceService.getAllItems(Rule.class);
         scoringRule = rules.stream().filter(rule -> rule.getItemId().equals(pastEventCondition.getParameter("generatedPropertyKey"))).findFirst().get();
@@ -654,7 +654,7 @@ public class SegmentIT extends BaseIT {
 
         // Remove scoring
         segmentService.removeSegmentDefinition(scoring.getItemId(), true);
-        refreshPersistence();
+        refreshPersistence(Segment.class);
         // Check linkedItems
         rules = persistenceService.getAllItems(Rule.class);
         boolean isRule = rules.stream().anyMatch(rule -> rule.getItemId().equals(pastEventCondition.getParameter("generatedPropertyKey")));
diff --git a/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java
index 159084e00..7d95a2749 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java
@@ -109,7 +109,8 @@ public class DefinitionsServiceImpl implements DefinitionsService, SynchronousBu
     public void reloadTypes(boolean refresh) {
         try {
             if (refresh) {
-                persistenceService.refresh();
+                persistenceService.refreshIndex(ConditionType.class, null);
+                persistenceService.refreshIndex(ActionType.class, null);
             }
             loadConditionTypesFromPersistence();
             loadActionTypesFromPersistence();
diff --git a/services/src/main/java/org/apache/unomi/services/impl/goals/GoalsServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/goals/GoalsServiceImpl.java
index 37da7a314..76cfc0024 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/goals/GoalsServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/goals/GoalsServiceImpl.java
@@ -549,7 +549,7 @@ public class GoalsServiceImpl implements GoalsService, SynchronousBundleListener
     @Override
     public PartialList<CampaignEvent> getEvents(Query query) {
         if(query.isForceRefresh()){
-            persistenceService.refresh();
+            persistenceService.refreshIndex(CampaignEvent.class, null);
         }
         definitionsService.resolveConditionType(query.getCondition());
         return persistenceService.query(query.getCondition(), query.getSortby(), CampaignEvent.class, query.getOffset(), query.getLimit());
diff --git a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
index 76c175955..1b4aff4d5 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
@@ -277,7 +277,7 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
     public void reloadPropertyTypes(boolean refresh) {
         try {
             if (refresh) {
-                persistenceService.refresh();
+                persistenceService.refreshIndex(PropertyType.class, null);
             }
             loadPropertyTypesFromPersistence();
         } catch (Throwable t) {
diff --git a/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
index 46fc3c94d..bb02955e0 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/rules/RulesServiceImpl.java
@@ -369,7 +369,7 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
 
     public PartialList<Metadata> getRuleMetadatas(Query query) {
         if (query.isForceRefresh()) {
-            persistenceService.refresh();
+            persistenceService.refreshIndex(Rule.class, null);
         }
         definitionsService.resolveConditionType(query.getCondition());
         List<Metadata> descriptions = new LinkedList<>();
@@ -382,7 +382,7 @@ public class RulesServiceImpl implements RulesService, EventListenerService, Syn
 
     public PartialList<Rule> getRuleDetails(Query query) {
         if (query.isForceRefresh()) {
-            persistenceService.refresh();
+            persistenceService.refreshIndex(Rule.class, null);
         }
         definitionsService.resolveConditionType(query.getCondition());
         PartialList<Rule> rules = persistenceService.query(query.getCondition(), query.getSortby(), Rule.class, query.getOffset(), query.getLimit());