mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Better comments on DeduplicateStateEntries
This commit is contained in:
parent
b22731cdcd
commit
d96780c376
|
|
@ -74,22 +74,23 @@ func (a StateEntry) LessThan(b StateEntry) bool {
|
||||||
return a.EventNID < b.EventNID
|
return a.EventNID < b.EventNID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deduplicate ensures that the latest NIDs are always presented in the case of duplicates.
|
// Deduplicate takes a set of state entries and ensures that there are no
|
||||||
|
// duplicate (event type, state key) tuples. If there are then we dedupe
|
||||||
|
// them, making sure that the latest/highest NIDs are always chosen.
|
||||||
func DeduplicateStateEntries(a []StateEntry) []StateEntry {
|
func DeduplicateStateEntries(a []StateEntry) []StateEntry {
|
||||||
result := a
|
|
||||||
if len(a) < 2 {
|
if len(a) < 2 {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
sort.SliceStable(a, func(i, j int) bool {
|
sort.SliceStable(a, func(i, j int) bool {
|
||||||
return a[i].LessThan(a[j])
|
return a[i].LessThan(a[j])
|
||||||
})
|
})
|
||||||
for i := 0; i < len(result)-1; i++ {
|
for i := 0; i < len(a)-1; i++ {
|
||||||
if result[i].StateKeyTuple == result[i+1].StateKeyTuple {
|
if a[i].StateKeyTuple == a[i+1].StateKeyTuple {
|
||||||
result = append(result[:i], result[i+1:]...)
|
a = append(a[:i], a[i+1:]...)
|
||||||
i--
|
i--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateAtEvent is the state before and after a matrix event.
|
// StateAtEvent is the state before and after a matrix event.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue