fix: improve performance by reducing full table scans (#4684)

* use instance id on update in projections

* create index on domain in instance_domain projection

* add missing instanceID filter to app queries
This commit is contained in:
Livio Spring
2022-11-10 11:59:33 +01:00
committed by GitHub
parent ac66a54df9
commit 78ae64471a
71 changed files with 683 additions and 399 deletions

View File

@@ -23,7 +23,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
want wantReduce
}{
{
name: "org.reduceAdded.Title",
name: "org reduceAdded Title",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextSetEventType),
@@ -62,7 +62,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceAdded.PreHeader",
name: "org reduceAdded PreHeader",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextSetEventType),
@@ -101,7 +101,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceAdded.Subject",
name: "org reduceAdded Subject",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextSetEventType),
@@ -140,7 +140,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceAdded.Greeting",
name: "org reduceAdded Greeting",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextSetEventType),
@@ -179,7 +179,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceAdded.Text",
name: "org reduceAdded Text",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextSetEventType),
@@ -218,7 +218,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceAdded.ButtonText",
name: "org reduceAdded ButtonText",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextSetEventType),
@@ -257,7 +257,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceAdded.Footer",
name: "org reduceAdded Footer",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextSetEventType),
@@ -296,7 +296,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved.Title",
name: "org reduceRemoved Title",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextRemovedEventType),
@@ -316,7 +316,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, title) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, title) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -324,6 +324,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -331,7 +332,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceInstanceRemoved",
name: "instance reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
@@ -357,7 +358,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved.PreHeader",
name: "org reduceRemoved PreHeader",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextRemovedEventType),
@@ -377,7 +378,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, pre_header) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, pre_header) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -385,6 +386,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -392,7 +394,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved.Subject",
name: "org reduceRemoved Subject",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextRemovedEventType),
@@ -412,7 +414,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, subject) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, subject) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -420,6 +422,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -427,7 +430,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved.Greeting",
name: "org reduceRemoved Greeting",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextRemovedEventType),
@@ -447,7 +450,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, greeting) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, greeting) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -455,6 +458,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -462,7 +466,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved.Text",
name: "org reduceRemoved Text",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextRemovedEventType),
@@ -482,7 +486,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, text) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, text) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -490,6 +494,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -497,7 +502,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved.ButtonText",
name: "org reduceRemoved ButtonText",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextRemovedEventType),
@@ -517,7 +522,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, button_text) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, button_text) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -525,6 +530,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -532,7 +538,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved.Footer",
name: "org reduceRemoved Footer",
args: args{
event: getEvent(testEvent(
repository.EventType(org.CustomTextRemovedEventType),
@@ -552,7 +558,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, footer_text) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, footer_text) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -560,6 +566,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -567,7 +574,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved",
name: "org reduceRemoved",
reduce: (&messageTextProjection{}).reduceTemplateRemoved,
args: args{
event: getEvent(testEvent(
@@ -587,11 +594,12 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.message_texts WHERE (aggregate_id = $1) AND (type = $2) AND (language = $3)",
expectedStmt: "DELETE FROM projections.message_texts WHERE (aggregate_id = $1) AND (type = $2) AND (language = $3) AND (instance_id = $4)",
expectedArgs: []interface{}{
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},
@@ -599,7 +607,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceAdded",
name: "instance reduceAdded",
reduce: (&messageTextProjection{}).reduceAdded,
args: args{
event: getEvent(testEvent(
@@ -638,7 +646,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceRemoved.Title",
name: "instance reduceRemoved Title",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.CustomTextRemovedEventType),
@@ -658,7 +666,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, title) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6)",
expectedStmt: "UPDATE projections.message_texts SET (change_date, sequence, title) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (type = $5) AND (language = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -666,6 +674,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
"agg-id",
"InitCode",
"en",
"instance-id",
},
},
},