This is an automated email from the ASF dual-hosted git repository.
jkevan pushed a commit to branch optimizeProfileQueryDuringSegmentRemove
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to
refs/heads/optimizeProfileQueryDuringSegmentRemove by this push:
new 8f6b1ccef UNOMI-557: Optimize the profile update during segment
deletion
8f6b1ccef is described below
commit 8f6b1ccefd7c4e4f136431ebcf4199ce5c493831
Author: Kevan <[email protected]>
AuthorDate: Wed Jun 1 19:08:35 2022 +0200
UNOMI-557: Optimize the profile update during segment deletion
---
itests/src/test/java/org/apache/unomi/itests/SegmentIT.java | 4 ++--
itests/src/test/resources/schemas/event-dummy-valid.json | 9 ++++++---
.../unomi/services/impl/segments/SegmentServiceImpl.java | 12 ++++++------
3 files changed, 14 insertions(+), 11 deletions(-)
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 329555bde..038e45431 100644
--- a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
@@ -185,7 +185,7 @@ public class SegmentIT extends BaseIT {
// insure the profile that did the past event condition is correctly
engaged in the segment.
keepTrying("Profile should be engaged in the segment", () ->
profileService.load("test_profile_id"),
- loadedProfile -> loadedProfile != null &&
loadedProfile.getSegments() != null &&
loadedProfile.getSegments().contains("add-delete-segment-test"), 2000, 20);
+ loadedProfile -> loadedProfile != null &&
loadedProfile.getSegments() != null &&
loadedProfile.getSegments().contains("add-delete-segment-test"), 1000, 20);
// delete the segment
segmentService.removeSegmentDefinition("add-delete-segment-test",
false);
@@ -193,7 +193,7 @@ public class SegmentIT extends BaseIT {
// insure the profile is not engaged anymore after segment deleted
keepTrying("Profile should not be engaged in the segment anymore after
the segment have been deleted", () -> profileService.load("test_profile_id"),
- loadedProfile -> loadedProfile != null &&
(loadedProfile.getSegments() == null ||
!loadedProfile.getSegments().contains("add-delete-segment-test")), 2000, 20);
+ loadedProfile -> loadedProfile != null &&
(loadedProfile.getSegments() == null ||
!loadedProfile.getSegments().contains("add-delete-segment-test")), 1000, 20);
}
@Test
diff --git a/itests/src/test/resources/schemas/event-dummy-valid.json
b/itests/src/test/resources/schemas/event-dummy-valid.json
index ae55bdf33..1cdad7876 100644
--- a/itests/src/test/resources/schemas/event-dummy-valid.json
+++ b/itests/src/test/resources/schemas/event-dummy-valid.json
@@ -1,7 +1,10 @@
{
- "eventType":"dummy",
- "scope":"dummy_scope",
- "properties": {
+ "eventType":"form",
+ "scope":"digitall",
+ "flattenedProperties": {
+ "formFields": {
+ "f"
+ },
"workspace": "dummy_workspace",
"path": "dummy/path"
}
diff --git
a/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java
b/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java
index 6a86a8c44..90fda2b29 100644
---
a/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java
+++
b/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java
@@ -391,7 +391,7 @@ public class SegmentServiceImpl extends AbstractServiceImpl
implements SegmentSe
segmentCondition.setParameter("propertyName", "segments");
segmentCondition.setParameter("comparisonOperator", "equals");
segmentCondition.setParameter("propertyValue", segmentId);
- updateProfilesSegment(segmentCondition, segmentId, false);
+ updateProfilesSegment(segmentCondition, segmentId, false, false);
// update impacted segments
for (Segment segment : impactedSegments) {
@@ -1074,15 +1074,15 @@ public class SegmentServiceImpl extends
AbstractServiceImpl implements SegmentSe
profilesToRemoveSubConditions.add(notNewSegmentCondition);
profilesToRemoveCondition.setParameter("subConditions",
profilesToRemoveSubConditions);
- updatedProfileCount +=
updateProfilesSegment(profilesToAddCondition, segmentId, true);
- updatedProfileCount +=
updateProfilesSegment(profilesToRemoveCondition, segmentId, false);
+ updatedProfileCount +=
updateProfilesSegment(profilesToAddCondition, segmentId, true,
sendProfileUpdateEventForSegmentUpdate);
+ updatedProfileCount +=
updateProfilesSegment(profilesToRemoveCondition, segmentId, false,
sendProfileUpdateEventForSegmentUpdate);
} else {
- updatedProfileCount += updateProfilesSegment(segmentCondition,
segmentId, false);
+ updatedProfileCount += updateProfilesSegment(segmentCondition,
segmentId, false, sendProfileUpdateEventForSegmentUpdate);
}
logger.info("{} profiles updated in {}ms", updatedProfileCount,
System.currentTimeMillis() - updateProfilesForSegmentStartTime);
}
- private long updateProfilesSegment(Condition profilesToUpdateCondition,
String segmentId, boolean isAdd) {
+ private long updateProfilesSegment(Condition profilesToUpdateCondition,
String segmentId, boolean isAdd, boolean sendProfileUpdateEvent) {
long updatedProfileCount = 0;
PartialList<Profile> profiles =
persistenceService.query(profilesToUpdateCondition, null, Profile.class, 0,
segmentUpdateBatchSize, "10m");
@@ -1096,7 +1096,7 @@ public class SegmentServiceImpl extends
AbstractServiceImpl implements SegmentSe
persistenceService.update(profileToUpdate, null,
Profile.class, sourceMap);
}
}
- if (sendProfileUpdateEventForSegmentUpdate)
+ if (sendProfileUpdateEvent)
sendProfileUpdatedEvent(profiles.getList());
updatedProfileCount += profiles.size();