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

@@ -22,7 +22,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
want wantReduce
}{
{
name: "instance.reduceNotificationProviderFileAdded",
name: "instance reduceNotificationProviderFileAdded",
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded,
args: args{
event: getEvent(testEvent(
@@ -58,7 +58,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceNotificationProviderFileChanged",
name: "instance reduceNotificationProviderFileChanged",
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged,
args: args{
event: getEvent(testEvent(
@@ -76,13 +76,14 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)",
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5) AND (instance_id = $6)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
true,
"agg-id",
domain.NotificationProviderTypeFile,
"instance-id",
},
},
},
@@ -90,7 +91,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceNotificationProviderFileRemoved",
name: "instance reduceNotificationProviderFileRemoved",
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved,
args: args{
event: getEvent(testEvent(
@@ -106,10 +107,11 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)",
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2) AND (instance_id = $3)",
expectedArgs: []interface{}{
"agg-id",
domain.NotificationProviderTypeFile,
"instance-id",
},
},
},
@@ -117,7 +119,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceNotificationProviderLogAdded",
name: "instance reduceNotificationProviderLogAdded",
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded,
args: args{
event: getEvent(testEvent(
@@ -153,7 +155,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceNotificationProviderLogChanged",
name: "instance reduceNotificationProviderLogChanged",
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged,
args: args{
event: getEvent(testEvent(
@@ -171,13 +173,14 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)",
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5) AND (instance_id = $6)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
true,
"agg-id",
domain.NotificationProviderTypeLog,
"instance-id",
},
},
},
@@ -185,7 +188,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceNotificationProviderLogRemoved",
name: "instance reduceNotificationProviderLogRemoved",
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved,
args: args{
event: getEvent(testEvent(
@@ -201,10 +204,11 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)",
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2) AND (instance_id = $3)",
expectedArgs: []interface{}{
"agg-id",
domain.NotificationProviderTypeLog,
"instance-id",
},
},
},
@@ -212,7 +216,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceInstanceRemoved",
name: "instance reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),