Skip to content

Commit

Permalink
fix(redis): add destination_id in the key
Browse files Browse the repository at this point in the history
while preparing the event for profiles<>redis store
  • Loading branch information
debanjan97 committed Sep 14, 2023
1 parent 9fc4545 commit 55629d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/v0/destinations/redis/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const isSubEventTypeProfiles = (message) => {
return sources.profiles_entity && sources.profiles_id_type && sources.profiles_model;
};

const transforrmSubEventTypeProfiles = (message, workspaceId) => {
const transformSubEventTypeProfiles = (message, workspaceId, destinationId) => {
// form the hash
const hash = `${workspaceId}:${message.context.sources.profiles_entity}:${message.context.sources.profiles_id_type}:${message.userId}`;
const hash = `${workspaceId}:${destinationId}:${message.context.sources.profiles_entity}:${message.context.sources.profiles_id_type}:${message.userId}`;
const key = `${message.context.sources.profiles_model}`;
const value = JSON.stringify(message.traits);
return {
Expand All @@ -59,11 +59,12 @@ const process = (event) => {
}

const { prefix } = destination.Config;
const destinationId = destination.ID;
const keyPrefix = isEmpty(prefix) ? '' : `${prefix.trim()}:`;

if (isSubEventTypeProfiles(message)) {
const { workspaceId } = metadata;
return transforrmSubEventTypeProfiles(message, workspaceId);
return transformSubEventTypeProfiles(message, workspaceId, destinationId);
}

const hmap = {
Expand Down
2 changes: 1 addition & 1 deletion test/__tests__/data/redis_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
},
{
"message": {
"hash": "some-workspace-id:some-entity:some-id-type:some-user-id",
"hash": "some-workspace-id:1WhcOCGgj9asZu850HvugU2C3Aq:some-entity:some-id-type:some-user-id",
"key": "some-model",
"value": "{\"MODEL_ID\":\"1691755780\",\"VALID_AT\":\"2023-08-11T11:32:44.963062Z\",\"USER_MAIN_ID\":\"rid5530313526204a95efe71d98cd17d5a1\",\"CHURN_SCORE_7_DAYS\":0.027986,\"PERCENTILE_CHURN_SCORE_7_DAYS\":0}"
},
Expand Down

0 comments on commit 55629d6

Please sign in to comment.