jsinovassin commented on code in PR #659:
URL: https://github.com/apache/unomi/pull/659#discussion_r1611231889


##########
services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java:
##########
@@ -986,31 +986,35 @@ public void recalculatePastEventConditions() {
      *
      * @param eventCountByProfile the events count per profileId map
      * @param propertyKey         the generate property key for this past 
event condition, to keep track of the count in the profile
-     * @return the list of profiles for witch the count of event occurrences 
have been updated.
+     * @return the set of profiles for witch the count of event occurrences 
have been updated.
      */
     private Set<String> updatePastEventOccurrencesOnProfiles(Map<String, Long> 
eventCountByProfile, String propertyKey) {
         Set<String> profilesUpdated = new HashSet<>();
-        Map<Item, Map> batch = new HashMap<>();
+        Map<String, Map[]> batch = new HashMap<>();
         Iterator<Map.Entry<String, Long>> entryIterator = 
eventCountByProfile.entrySet().iterator();
+
         while (entryIterator.hasNext()) {
             Map.Entry<String, Long> entry = entryIterator.next();
             String profileId = entry.getKey();
             if (!profileId.startsWith("_")) {
-                Map<String, Long> pastEventCounts = new HashMap<>();
-                pastEventCounts.put(propertyKey, entry.getValue());
-                Map<String, Object> systemProperties = new HashMap<>();
-                systemProperties.put("pastEvents", pastEventCounts);
-                systemProperties.put("lastUpdated", new Date());
-
-                Profile profile = new Profile();
-                profile.setItemId(profileId);
-                batch.put(profile, 
Collections.singletonMap("systemProperties", systemProperties));
+                Map<String, Object> scriptParams = new HashMap<>();
+                scriptParams.put("pastEventKey", propertyKey);
+                scriptParams.put("valueToAdd", entry.getValue());
+                Map<String, Object>[] params = new Map[]{scriptParams};
+                batch.put(profileId, params);
                 profilesUpdated.add(profileId);
             }
 
-            if (batch.size() == segmentUpdateBatchSize || 
(!entryIterator.hasNext() && batch.size() > 0)) {
+
+
+
+            if (batch.size() == segmentUpdateBatchSize || 
(!entryIterator.hasNext() && !batch.isEmpty())) {
                 try {
-                    persistenceService.update(batch, Profile.class);
+                    batch.forEach((id, params) -> {
+                        Condition profileIdCondition = 
conditionHelper.createProfilePropertyCondition("itemId", "equals", id, 
"propertyValue");
+                        Condition[] conditions = new 
Condition[]{profileIdCondition};
+                        
persistenceService.updateWithQueryAndStoredScript(Profile.class, new 
String[]{"updatePastEventOccurences"}, params, conditions);
+                    });

Review Comment:
   Updated!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to