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 TestPrivacyPolicyProjection_reduces(t *testing.T) {
want wantReduce
}{
{
name: "org.reduceAdded",
name: "org reduceAdded",
args: args{
event: getEvent(testEvent(
repository.EventType(org.PrivacyPolicyAddedEventType),
@@ -63,7 +63,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceChanged",
name: "org reduceChanged",
reduce: (&privacyPolicyProjection{}).reduceChanged,
args: args{
event: getEvent(testEvent(
@@ -83,7 +83,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.privacy_policies SET (change_date, sequence, privacy_link, tos_link, help_link) = ($1, $2, $3, $4, $5) WHERE (id = $6)",
expectedStmt: "UPDATE projections.privacy_policies SET (change_date, sequence, privacy_link, tos_link, help_link) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -91,6 +91,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"http://tos.link",
"http://help.link",
"agg-id",
"instance-id",
},
},
},
@@ -98,7 +99,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
},
},
{
name: "org.reduceRemoved",
name: "org reduceRemoved",
reduce: (&privacyPolicyProjection{}).reduceRemoved,
args: args{
event: getEvent(testEvent(
@@ -114,16 +115,17 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.privacy_policies WHERE (id = $1)",
expectedStmt: "DELETE FROM projections.privacy_policies WHERE (id = $1) AND (instance_id = $2)",
expectedArgs: []interface{}{
"agg-id",
"instance-id",
},
},
},
},
},
}, {
name: "instance.reduceInstanceRemoved",
name: "instance reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
@@ -149,7 +151,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceAdded",
name: "instance reduceAdded",
reduce: (&privacyPolicyProjection{}).reduceAdded,
args: args{
event: getEvent(testEvent(
@@ -189,7 +191,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceChanged",
name: "instance reduceChanged",
reduce: (&privacyPolicyProjection{}).reduceChanged,
args: args{
event: getEvent(testEvent(
@@ -209,7 +211,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.privacy_policies SET (change_date, sequence, privacy_link, tos_link, help_link) = ($1, $2, $3, $4, $5) WHERE (id = $6)",
expectedStmt: "UPDATE projections.privacy_policies SET (change_date, sequence, privacy_link, tos_link, help_link) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -217,6 +219,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"http://tos.link",
"http://help.link",
"agg-id",
"instance-id",
},
},
},