From b3db3f19a2f0b584746842ae9fe809e02e5f924c Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 9 Mar 2017 11:54:22 +0000 Subject: [PATCH] Comment on why we sort the tuples --- .../matrix-org/dendrite/roomserver/storage/state_block_table.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/github.com/matrix-org/dendrite/roomserver/storage/state_block_table.go b/src/github.com/matrix-org/dendrite/roomserver/storage/state_block_table.go index b265ddbaf..53494bf68 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/storage/state_block_table.go +++ b/src/github.com/matrix-org/dendrite/roomserver/storage/state_block_table.go @@ -153,6 +153,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries( stateBlockNIDs []types.StateBlockNID, stateKeyTuples []types.StateKeyTuple, ) ([]types.StateEntryList, error) { tuples := stateKeyTupleSorter(stateKeyTuples) + // Sort the tuples so that we can run binary search against them as we filter the rows returned by the db. sort.Sort(tuples) eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays() @@ -185,6 +186,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries( entry.EventStateKeyNID = types.EventStateKeyNID(eventStateKeyNID) entry.EventNID = types.EventNID(eventNID) + // We can use binary search here because we sorted the tuples earlier if !tuples.contains(entry.StateKeyTuple) { // The select will return the cross product of types and state keys. // So we need to check if type of the entry is in the list.