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

@@ -40,9 +40,10 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.project_grants2 WHERE (project_id = $1)",
expectedStmt: "DELETE FROM projections.project_grants2 WHERE (project_id = $1) AND (instance_id = $2)",
expectedArgs: []interface{}{
"agg-id",
"instance-id",
},
},
},
@@ -50,7 +51,7 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
},
},
{
name: "instance.reduceInstanceRemoved",
name: "instance reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
@@ -92,10 +93,11 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.project_grants2 WHERE (grant_id = $1) AND (project_id = $2)",
expectedStmt: "DELETE FROM projections.project_grants2 WHERE (grant_id = $1) AND (project_id = $2) AND (instance_id = $3)",
expectedArgs: []interface{}{
"grant-id",
"agg-id",
"instance-id",
},
},
},
@@ -119,13 +121,14 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5)",
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5) AND (instance_id = $6)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
domain.ProjectGrantStateActive,
"grant-id",
"agg-id",
"instance-id",
},
},
},
@@ -149,13 +152,14 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5)",
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5) AND (instance_id = $6)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
domain.ProjectGrantStateInactive,
"grant-id",
"agg-id",
"instance-id",
},
},
},
@@ -179,13 +183,14 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, granted_role_keys) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5)",
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, granted_role_keys) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5) AND (instance_id = $6)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
database.StringArray{"admin", "user"},
"grant-id",
"agg-id",
"instance-id",
},
},
},
@@ -209,13 +214,14 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, granted_role_keys) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5)",
expectedStmt: "UPDATE projections.project_grants2 SET (change_date, sequence, granted_role_keys) = ($1, $2, $3) WHERE (grant_id = $4) AND (project_id = $5) AND (instance_id = $6)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
database.StringArray{"admin", "user"},
"grant-id",
"agg-id",
"instance-id",
},
},
},