You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2020/07/27 08:04:36 UTC
[unomi] 04/11: refresh profile index
This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch unomi-1.5.x
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 29f603a7f82ae96519f88abcbce7ba17c4df6475
Author: Gilad Weinbach <gw...@yotpo.com>
AuthorDate: Mon Jun 29 18:35:12 2020 +0300
refresh profile index
(cherry picked from commit 554ea6e6993ed0e268f7c23e5e7ecb332f3a72dc)
---
.../ElasticSearchPersistenceServiceImpl.java | 17 ++++++++++++++++-
.../unomi/persistence/spi/PersistenceService.java | 9 +++++++++
.../services/impl/profiles/ProfileServiceImpl.java | 6 ++----
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index 456a930..aef7b34 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -1732,7 +1732,6 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
return routing;
}
-
@Override
public void refresh() {
new InClassLoaderExecute<Boolean>(metricsService, this.getClass().getName() + ".refresh") {
@@ -1748,10 +1747,26 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
return true;
}
}.catchingExecuteInClassLoader(true);
+ }
+ @Override
+ public <T extends Item> void refreshIndex(Class<T> clazz, Date dateHint){
+ new InClassLoaderExecute<Boolean>(metricsService, this.getClass().getName() + ".refreshIndex") {
+ protected Boolean execute(Object... args) {
+ try {
+ String itemType = Item.getItemType(clazz);
+ String index = getIndex(itemType, dateHint);
+ client.indices().refresh(Requests.refreshRequest(index), RequestOptions.DEFAULT);
+ } catch (IOException e) {
+ e.printStackTrace();//TODO manage ES7
+ }
+ return true;
+ }
+ }.catchingExecuteInClassLoader(true);
}
+
@Override
public void purge(final Date date) {
new InClassLoaderExecute<Object>(metricsService, this.getClass().getName() + ".purgeWithDate") {
diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
index 7311353..80bf444 100644
--- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
+++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
@@ -443,6 +443,15 @@ public interface PersistenceService {
void refresh();
/**
+ * Updates the persistence's engine specific index.
+ *
+ * @param clazz will use an index by class type
+ * @param dateHint for index with time, can be null
+ * @param <T> a class that extends Item
+ */
+ <T extends Item> void refreshIndex(Class<T> clazz, Date dateHint);
+
+ /**
* Purges all data in the context server up to the specified date, not included.
*
* @param date the date (not included) before which we want to erase all data
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 c0269ed..42873ea 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
@@ -524,11 +524,9 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
profile.setSystemProperty("lastUpdated", new Date());
if (persistenceService.save(profile)) {
if (forceRefresh) {
- // triggering a load will force an in-place refresh, that may be expensive in performance but will make data immediately available.
- return persistenceService.load(profile.getItemId(), Profile.class);
- } else {
- return profile;
+ persistenceService.refreshIndex(Profile.class, null);
}
+ return profile;
}
return null;
}