Can't you use `ctx.getAffectedKeys()` here?