mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 15:03:09 -06:00
Comment on why we sort the tuples
This commit is contained in:
parent
322ee668ce
commit
b3db3f19a2
|
|
@ -153,6 +153,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
|
||||||
stateBlockNIDs []types.StateBlockNID, stateKeyTuples []types.StateKeyTuple,
|
stateBlockNIDs []types.StateBlockNID, stateKeyTuples []types.StateKeyTuple,
|
||||||
) ([]types.StateEntryList, error) {
|
) ([]types.StateEntryList, error) {
|
||||||
tuples := stateKeyTupleSorter(stateKeyTuples)
|
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)
|
sort.Sort(tuples)
|
||||||
|
|
||||||
eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays()
|
eventTypeNIDArray, eventStateKeyNIDArray := tuples.typesAndStateKeysAsArrays()
|
||||||
|
|
@ -185,6 +186,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
|
||||||
entry.EventStateKeyNID = types.EventStateKeyNID(eventStateKeyNID)
|
entry.EventStateKeyNID = types.EventStateKeyNID(eventStateKeyNID)
|
||||||
entry.EventNID = types.EventNID(eventNID)
|
entry.EventNID = types.EventNID(eventNID)
|
||||||
|
|
||||||
|
// We can use binary search here because we sorted the tuples earlier
|
||||||
if !tuples.contains(entry.StateKeyTuple) {
|
if !tuples.contains(entry.StateKeyTuple) {
|
||||||
// The select will return the cross product of types and state keys.
|
// 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.
|
// So we need to check if type of the entry is in the list.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue