Further optimization

This commit is contained in:
Till Faelligen 2023-01-02 10:20:28 +01:00
parent c915689d20
commit b9d947e438
No known key found for this signature in database
GPG key ID: ACCDC9606D472758

View file

@ -5,11 +5,10 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/internal/eventutil" "github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
userapi "github.com/matrix-org/dendrite/userapi/api" userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
) )
type DatabaseTransaction struct { type DatabaseTransaction struct {
@ -332,7 +331,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
stateNeededFiltered := stateNeeded stateNeededFiltered := stateNeeded
eventMapFiltered := eventMap eventMapFiltered := eventMap
// avoid hitting the database if the result would be the same as above // avoid hitting the database if the result would be the same as above
if stateFilter != nil { if !isStatefilterEmpty(stateFilter) {
stateNeededFiltered, eventMapFiltered, err = d.OutputEvents.SelectStateInRange(ctx, d.txn, r, stateFilter, allRoomIDs) stateNeededFiltered, eventMapFiltered, err = d.OutputEvents.SelectStateInRange(ctx, d.txn, r, stateFilter, allRoomIDs)
} }
@ -694,3 +693,26 @@ func (d *DatabaseTransaction) RelationsFor(ctx context.Context, roomID, eventID,
return events, prevBatch, nextBatch, nil return events, prevBatch, nextBatch, nil
} }
// TODO: move to GMSL
func isStatefilterEmpty(filter *gomatrixserverlib.StateFilter) bool {
if filter == nil {
return true
}
switch {
case filter.NotTypes != nil && len(*filter.NotTypes) > 0:
return false
case filter.Types != nil && len(*filter.Types) > 0:
return false
case filter.Senders != nil && len(*filter.Senders) > 0:
return false
case filter.NotSenders != nil && len(*filter.NotSenders) > 0:
return false
case filter.NotRooms != nil && len(*filter.NotRooms) > 0:
return false
case filter.ContainsURL != nil:
return false
default:
return true
}
}