[
https://issues.apache.org/jira/browse/UNOMI-1017?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18130920#comment-18130920
]
Romain Gauthier commented on UNOMI-1017:
----------------------------------------
The same replacement hits a counter per scope that is stored as a map, such as
{{properties.pageViewCount.<scope>}}, which {{incrementPropertyAction}}
increments. The web-tracker sample filters on this property
([index.html#L89|https://github.com/apache/unomi/blob/b795eaa693df0b398c683dad5d0aedb026c529af/extensions/web-tracker/wab/src/main/webapp/index.html#L89]).
* {{PropertyHelper.flatten}} descends into the map, so each scope becomes its
own key, for example {{pageViewCount.site1}}
([PropertyHelper.java#L283-L285|https://github.com/apache/unomi/blob/b795eaa693df0b398c683dad5d0aedb026c529af/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PropertyHelper.java#L283-L285]).
* {{mergeProfiles}} looks up the merge strategy with this flattened key
([ProfileServiceImpl.java#L772-L773|https://github.com/apache/unomi/blob/b795eaa693df0b398c683dad5d0aedb026c529af/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java#L772-L773]).
No property type has this ID, so {{defaultMergeStrategy}} keeps the count of
the last merged profile.
* Example: the master has 40 page views on {{site1}}, and the merged profiles
have 10 and then 16. After the merge, the master has 16, and the sum is 66.
A property type cannot fix this case, because its ID would have to contain the
scope, such as {{pageViewCount.site1}}. The fix needs a lookup on the parent
key {{pageViewCount}}, with a strategy that adds the values of the map by key.
The sum-by-key strategy proposed for {{interests}} can cover both the list and
the map.
> Profile merge replaces properties.interests instead of summing the points by
> key
> --------------------------------------------------------------------------------
>
> Key: UNOMI-1017
> URL: https://issues.apache.org/jira/browse/UNOMI-1017
> Project: Apache Unomi
> Issue Type: Bug
> Components: unomi(-core)
> Affects Versions: unomi-2.7.0, unomi-3.0.1
> Reporter: Romain Gauthier
> Priority: Major
>
> When profiles merge, the master profile loses its {{properties.interests}}
> list. The list of the last merged profile replaces it, and the interest
> points are not added.
> *Cause:* no profile property type declares {{interests}}, so
> {{mergeProfiles}} uses {{defaultMergeStrategy}}
> ([ProfileServiceImpl.java#L773|https://github.com/apache/unomi/blob/b795eaa693df0b398c683dad5d0aedb026c529af/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java#L773]).
> That executor sets each non-empty value with {{alwaysSet}}, so the last
> profile wins
> ([DefaultPropertyMergeStrategyExecutor.java#L28-L37|https://github.com/apache/unomi/blob/b795eaa693df0b398c683dad5d0aedb026c529af/services/src/main/java/org/apache/unomi/services/mergers/DefaultPropertyMergeStrategyExecutor.java#L28-L37]).
> *Proposed fix:* declare an {{interests}} profile property type with a new
> merge strategy that sums {{value}} by {{key}}. The mapping already declares
> the field
> ([profile.json#L50|https://github.com/apache/unomi/blob/b795eaa693df0b398c683dad5d0aedb026c529af/persistence-elasticsearch/core/src/main/resources/META-INF/cxs/mappings/profile.json#L50]).
> The existing {{addMergeStrategy}} does not fit, because it throws on a list
> ([AddPropertyMergeStrategyExecutor.java#L65|https://github.com/apache/unomi/blob/b795eaa693df0b398c683dad5d0aedb026c529af/services/src/main/java/org/apache/unomi/services/mergers/AddPropertyMergeStrategyExecutor.java#L65]).
> *Example:* the master has {{funds}} 30, and the merged profile has {{funds}}
> 5 and {{pension}} 7.
> {code:json}
> // master after the merge, today
> [{"key": "funds", "value": 5}, {"key": "pension", "value": 7}]
> // expected
> [{"key": "funds", "value": 35}, {"key": "pension", "value": 7}]
> {code}
> *Verified:* code reading on master {{b795eaa69}}, on {{unomi-root-3.0.1}} and
> on {{unomi-root-2.7.0}}, where the merge code is the same. No test run.
> Related: UNOMI-441 asks for a strategy that appends lists. An append keeps
> two {{funds}} entries and does not sum them.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)