Skip to content

Commit cdf9149

Browse files
committed
Group by full key with configurable override.
1 parent d3ab5fd commit cdf9149

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/flavors/job.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,25 @@ export const toCursorUpdateRequest = (rule) => faulty((uow) => ({
132132
}));
133133

134134
export const flushCursor = (rule) => (s) => {
135+
const {
136+
// By default group on a stringified version of the full key. If the key structure
137+
// differs in a users particular implementation or they want to group by something
138+
// else they can simply override this fn in their rule.
139+
cursorKeyFn = (uow) => `pk:${uow.event.raw.new.pk}|sk:${uow.event.raw.new.sk}`,
140+
} = rule;
141+
135142
/* istanbul ignore else */
136143
if (rule.toCursorUpdateRequest) {
137144
return s
138145
// Compact explicitly on PK here since we want to capture just the last event per PK in this
139146
// invocation after the query split. This handles the case where multiple cursor events
140147
// ended up in a single lambda invocation.
141-
.through(compact({ ...rule, compact: true }))
148+
.through(compact({
149+
...rule,
150+
compact: {
151+
group: (uow) => cursorKeyFn(uow),
152+
},
153+
}))
142154
.map(toCursorUpdateRequest(rule))
143155
.through(updateDynamoDB({
144156
...rule,

0 commit comments

Comments
 (0)